8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/refinery/cli.rb', line 8
def override(env)
if (view = env["view"]).present?
pattern = "{refinery#{File::SEPARATOR},}#{view.split("/").join(File::SEPARATOR)}*.{erb,builder}"
looking_for = ::Refinery::Plugins.registered.pathnames.map{|p| p.join("app", "views", pattern).to_s}
if (matches = looking_for.map{|d| Dir[d]}.flatten.compact.uniq).any?
matches.each do |match|
dir = match.split("/app/views/").last.split('/')
file = dir.pop dir = dir.join(File::SEPARATOR)
destination_dir = Rails.root.join("app", "views", dir)
FileUtils.mkdir_p(destination_dir)
FileUtils.cp match, (destination = File.join(destination_dir, file))
puts "Copied view template file to #{destination.gsub("#{Rails.root.to_s}#{File::SEPARATOR}", '')}"
end
else
puts "Couldn't match any view template files in any extensions like #{view}"
end
elsif (controller = env["controller"]).present?
pattern = "{refinery#{File::SEPARATOR},}#{controller.split("/").join(File::SEPARATOR)}*.rb"
looking_for = ::Refinery::Plugins.registered.pathnames.map{|p| p.join("app", "controllers", pattern).to_s}
if (matches = looking_for.map{|d| Dir[d]}.flatten.compact.uniq).any?
matches.each do |match|
dir = match.split("/app/controllers/").last.split('/')
file = dir.pop dir = dir.join(File::SEPARATOR)
destination_dir = Rails.root.join("app", "controllers", dir)
FileUtils.mkdir_p(destination_dir)
FileUtils.cp match, (destination = File.join(destination_dir, file))
puts "Copied controller file to #{destination.gsub("#{Rails.root.to_s}#{File::SEPARATOR}", '')}"
end
else
puts "Couldn't match any controller files in any extensions like #{controller}"
end
elsif (model = env["model"]).present?
pattern = "{refinery#{File::SEPARATOR},}#{model.split("/").join(File::SEPARATOR)}*.rb"
looking_for = ::Refinery::Plugins.registered.pathnames.map{|p| p.join("app", "models", pattern).to_s}
if (matches = looking_for.map{|d| Dir[d]}.flatten.compact.uniq).any?
matches.each do |match|
dir = match.split("/app/models/").last.split('/')
file = dir.pop dir = dir.join(File::SEPARATOR)
destination_dir = Rails.root.join("app", "models", dir)
FileUtils.mkdir_p(destination_dir)
FileUtils.cp match, (destination = File.join(destination_dir, file))
puts "Copied model file to #{destination.gsub("#{Rails.root.to_s}#{File::SEPARATOR}", '')}"
end
else
puts "Couldn't match any model files in any extensions like #{model}"
end
elsif (javascripts = env["javascript"]).present?
pattern = "#{javascripts.split("/").join(File::SEPARATOR)}*.js"
looking_for = ::Refinery::Plugins.registered.pathnames.map{|p| p.join("app", "assets", "javascripts", pattern).to_s}
if (matches = looking_for.map{|d| Dir[d]}.flatten.compact.uniq).any?
matches.each do |match|
dir = match.split("/app/assets/javascripts/").last.split('/')
file = dir.pop dir = dir.join(File::SEPARATOR)
destination_dir = Rails.root.join("app", "assets", "javascripts", dir)
FileUtils.mkdir_p(destination_dir)
FileUtils.cp match, (destination = File.join(destination_dir, file))
puts "Copied javascript file to #{destination.gsub("#{Rails.root.to_s}#{File::SEPARATOR}", '')}"
end
else
puts "Couldn't match any javascript files in any extensions like #{javascripts}"
end
elsif (stylesheets = env["stylesheet"]).present?
pattern = "#{stylesheets.split("/").join(File::SEPARATOR)}*.css.scss"
looking_for = ::Refinery::Plugins.registered.pathnames.map{|p| p.join("app", "assets", "stylesheets", pattern).to_s}
if (matches = looking_for.map{|d| Dir[d]}.flatten.compact.uniq).any?
matches.each do |match|
dir = match.split("/app/assets/stylesheets/").last.split('/')
file = dir.pop dir = dir.join(File::SEPARATOR)
destination_dir = Rails.root.join("app", "assets", "stylesheets", dir)
FileUtils.mkdir_p(destination_dir)
FileUtils.cp match, (destination = File.join(destination_dir, file))
puts "Copied stylesheet file to #{destination.gsub("#{Rails.root.to_s}#{File::SEPARATOR}", '')}"
end
else
puts "Couldn't match any stylesheet files in any extensions like #{stylesheets}"
end
else
puts "You didn't specify anything to override. Here are some examples:"
{
:view => ['pages/home', 'refinery/pages/home', '**/*menu', '_menu_branch'],
:javascript => %w(admin refinery/site_bar),
:stylesheet => %w(home refinery/site_bar),
:controller => %w(pages),
:model => %w(page refinery/page)
}.each do |type, examples|
examples.each do |example|
puts "rake refinery:override #{type}=#{example}"
end
end
end
end
|