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
|
# File 'lib/generators/refinerycms_generator.rb', line 11
def generate
self.silence_puts = true
if Rails.root == Refinery.root
say_status :'-- pretending to make changes that happen in an actual installation --', nil, :yellow
old_pretend = self.options[:pretend]
new_options = self.options.dup
new_options[:pretend] = true
self.options = new_options
end
unless self.options[:update]
%w(public/index.html app/views/layouts/application.html.erb public/javascripts/rails.js).each do |roadblock|
if (roadblock_path = Rails.root.join(roadblock)).file?
create_file "#{roadblock}.backup",
:verbose => true do roadblock_path.read end
remove_file roadblock_path, :verbose => true
end
end
%w(application.css formatting.css home.css theme.css).map{ |ss|
Refinery.roots('core').join('public', 'stylesheets', ss)
}.reject{|ss| !ss.file?}.each do |stylesheet|
copy_file stylesheet,
Rails.root.join('public', 'stylesheets', stylesheet.basename),
:verbose => true
end
copy_file Refinery.roots('core').join('public', 'javascripts', 'admin.js'),
Rails.root.join('public', 'javascripts', 'admin.js'),
:verbose => true
end
%w(development test production).map{|e| "config/environments/#{e}.rb"}.each do |env|
gsub_file env, %r{#.*config.serve_static_assets}, 'config.serve_static_assets', :verbose => false
gsub_file env, "serve_static_assets = false", "serve_static_assets = true # Refinery CMS requires this to be true", :verbose => false
unless Rails.root.join(env).read =~ %r{Refinery.rescue_not_found}
append_file env, "Refinery.rescue_not_found = #{env.split('/').last.split('.rb').first == 'production'}"
end
end
if Rails.root == Refinery.root
say_status :'-- finished pretending --', nil, :yellow
new_options = self.options.dup
new_options[:pretend] = old_pretend
self.options = new_options
end
create_file ".gitignore" unless Rails.root.join('.gitignore').file?
our_ignore_rules = self.class.source_root.join('.gitignore').read
our_ignore_rules = our_ignore_rules.split('# REFINERY CMS DEVELOPMENT').first if Rails.root != Refinery.root
append_file ".gitignore", our_ignore_rules
if (admin_base = Rails.root.join('app', 'controllers', 'admin', 'base_controller.rb')).file?
gsub_file admin_base,
"# You can extend refinery backend with your own functions here and they will likely not get overriden in an update.",
"",
:verbose => self.options[:update]
gsub_file admin_base, "< Refinery::AdminBaseController", "< ActionController::Base",
:verbose => self.options[:update]
end
append_file 'db/seeds.rb', :verbose => true do
self.class.source_root.join('db', 'seeds.rb').read
end
force_options = self.options.dup
force_options[:force] = self.options[:force] || self.options[:update]
self.options = force_options
existing_source_root = self.class.source_root
::Refinery::Plugins.registered.pathnames.reject{|p| !p.join('db').directory?}.each do |pathname|
self.class.source_root pathname
super
end
self.class.source_root existing_source_root
super
Pathname.glob(self.class.source_root.join('**', '*')).reject{|f|
f.directory? or f.to_s =~ /\/db\//
}.sort.each do |path|
copy_file path, path.to_s.gsub(self.class.source_root.to_s, Rails.root.to_s)
end
end
|