refinerycms-core 2.0.10 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/refinery/admin.js.erb +126 -234
  3. data/app/assets/javascripts/refinery/ajaxy_pagination.js.coffee +1 -1
  4. data/app/assets/javascripts/refinery/boot_wym.js.erb +4 -8
  5. data/app/assets/javascripts/refinery/core.js +1 -1
  6. data/app/assets/javascripts/refinery/interface.js.coffee.erb +3 -16
  7. data/app/assets/javascripts/refinery/modal_dialogs.js.erb +0 -3
  8. data/app/assets/javascripts/refinery/nestedsortables.js +312 -312
  9. data/app/assets/javascripts/refinery/refinery.js.erb +14 -15
  10. data/app/assets/javascripts/refinery/site_bar.js +3 -9
  11. data/app/assets/javascripts/refinery/sortable_list.js +145 -0
  12. data/app/assets/javascripts/refinery/sortable_menu.js.coffee +3 -4
  13. data/app/assets/javascripts/refinery/submit_continue.js.coffee.erb +1 -2
  14. data/app/assets/javascripts/refinery/tree.js +3 -3
  15. data/app/assets/javascripts/refinery/wymeditor.js +6 -6
  16. data/{public → app/assets/javascripts}/wymeditor/GPL-license.txt +0 -0
  17. data/{public → app/assets/javascripts}/wymeditor/MIT-license.txt +0 -0
  18. data/{public → app/assets/javascripts}/wymeditor/README +0 -0
  19. data/app/assets/javascripts/wymeditor/browsers/mozilla.js.erb +10 -11
  20. data/app/assets/javascripts/wymeditor/browsers/webkit.js.erb +17 -18
  21. data/app/assets/javascripts/wymeditor/classes.js.erb +3 -5
  22. data/app/assets/javascripts/wymeditor/functions.js.erb +5 -1
  23. data/app/assets/javascripts/wymeditor/prototypes.js.erb +0 -3
  24. data/app/assets/javascripts/wymeditor/setup.js.erb +5 -5
  25. data/app/assets/javascripts/wymeditor/skins/refinery/skin.js +1 -4
  26. data/app/assets/javascripts/wymeditor/validators.js.erb +3 -2
  27. data/app/assets/stylesheets/{formatting.css.scss → refinery/formatting.css.scss} +0 -0
  28. data/app/assets/stylesheets/refinery/layout.css.scss +41 -11
  29. data/app/assets/stylesheets/{theme.css.scss → refinery/theme.css.scss} +0 -0
  30. data/app/controllers/refinery/sitemap_controller.rb +1 -5
  31. data/app/helpers/refinery/admin_helper.rb +6 -0
  32. data/app/helpers/refinery/image_helper.rb +2 -1
  33. data/app/helpers/refinery/menu_helper.rb +0 -49
  34. data/app/helpers/refinery/meta_helper.rb +7 -3
  35. data/app/helpers/refinery/site_bar_helper.rb +3 -15
  36. data/app/models/refinery/core/base_model.rb +2 -0
  37. data/{lib → app/presenters}/refinery/base_presenter.rb +1 -2
  38. data/app/views/layouts/application.html.erb +8 -7
  39. data/app/views/refinery/_content_page.html.erb +1 -1
  40. data/app/views/refinery/_google_analytics.html.erb +12 -5
  41. data/app/views/refinery/_head.html.erb +11 -15
  42. data/app/views/refinery/_header.html.erb +1 -4
  43. data/app/views/refinery/_javascripts.html.erb +14 -8
  44. data/app/views/refinery/_site_bar.html.erb +4 -4
  45. data/app/views/refinery/admin/_form_advanced_options_menu.html.erb +12 -0
  46. data/app/views/refinery/admin/_javascripts.html.erb +13 -1
  47. data/app/views/refinery/admin/_locale_picker.html.erb +11 -0
  48. data/app/views/refinery/admin/_make_sortable.html.erb +8 -5
  49. data/app/views/refinery/admin/_search.html.erb +1 -7
  50. data/app/views/refinery/admin/_search_header.html.erb +1 -0
  51. data/app/views/refinery/admin/_wysiwyg.html.erb +16 -0
  52. data/config/initializers/will_paginate_monkeypatch.rb +1 -1
  53. data/config/locales/bg.yml +5 -1
  54. data/config/locales/cs.yml +5 -1
  55. data/config/locales/da.yml +5 -1
  56. data/config/locales/de.yml +7 -3
  57. data/config/locales/el.yml +5 -1
  58. data/config/locales/en.yml +7 -1
  59. data/config/locales/es.yml +5 -1
  60. data/config/locales/fi.yml +5 -1
  61. data/config/locales/fr.yml +5 -1
  62. data/config/locales/hu.yml +82 -0
  63. data/config/locales/it.yml +38 -34
  64. data/config/locales/ja.yml +5 -1
  65. data/config/locales/ko.yml +5 -1
  66. data/config/locales/lt.yml +5 -1
  67. data/config/locales/lv.yml +5 -1
  68. data/config/locales/nb.yml +5 -1
  69. data/config/locales/nl.yml +36 -29
  70. data/config/locales/pl.yml +8 -1
  71. data/config/locales/pt-BR.yml +7 -3
  72. data/config/locales/pt.yml +82 -0
  73. data/config/locales/rs.yml +5 -1
  74. data/config/locales/ru.yml +5 -1
  75. data/config/locales/sk.yml +10 -3
  76. data/config/locales/sl.yml +5 -1
  77. data/config/locales/sv.yml +5 -1
  78. data/config/locales/tr.yml +82 -0
  79. data/config/locales/uk.yml +77 -0
  80. data/config/locales/vi.yml +5 -1
  81. data/config/locales/zh-CN.yml +5 -1
  82. data/config/locales/zh-TW.yml +5 -1
  83. data/config/routes.rb +3 -3
  84. data/lib/generators/refinery/cms/cms_generator.rb +29 -0
  85. data/lib/generators/refinery/cms/templates/.gitignore +1 -0
  86. data/lib/generators/refinery/cms/templates/app/views/sitemap/index.xml.builder +13 -13
  87. data/lib/generators/refinery/core/templates/config/initializers/refinery/core.rb.erb +8 -12
  88. data/lib/generators/refinery/dummy/templates/rails/database.yml +3 -3
  89. data/lib/generators/refinery/engine/engine_generator.rb +8 -12
  90. data/lib/generators/refinery/engine/templates/Gemfile +5 -39
  91. data/lib/generators/refinery/engine/templates/app/controllers/refinery/namespace/admin/plural_name_controller.rb.erb +4 -4
  92. data/lib/generators/refinery/engine/templates/app/models/refinery/namespace/singular_name.rb.erb +2 -3
  93. data/lib/generators/refinery/engine/templates/app/views/refinery/namespace/admin/plural_name/_actions.html.erb +1 -1
  94. data/lib/generators/refinery/engine/templates/app/views/refinery/namespace/admin/plural_name/_form.html.erb +31 -33
  95. data/lib/generators/refinery/engine/templates/app/views/refinery/namespace/admin/plural_name/_records.html.erb +1 -3
  96. data/lib/generators/refinery/engine/templates/app/views/refinery/namespace/admin/plural_name/_singular_name.html.erb +2 -2
  97. data/lib/generators/refinery/engine/templates/app/views/refinery/namespace/admin/plural_name/index.html.erb +1 -1
  98. data/lib/generators/refinery/engine/templates/config/locales/cs.yml +28 -0
  99. data/lib/generators/refinery/engine/templates/config/locales/it.yml +28 -0
  100. data/lib/generators/refinery/engine/templates/config/locales/nl.yml +6 -6
  101. data/lib/generators/refinery/engine/templates/config/locales/tr.yml +28 -0
  102. data/lib/generators/refinery/engine/templates/config/routes.rb.erb +2 -2
  103. data/lib/generators/refinery/engine/templates/db/seeds.rb.erb +1 -1
  104. data/lib/generators/refinery/engine/templates/lib/generators/refinery/extension_plural_name_generator.rb.erb +1 -1
  105. data/lib/generators/refinery/engine/templates/lib/refinery/plural_name/engine.rb.erb +1 -1
  106. data/lib/generators/refinery/engine/templates/spec/{requests → features}/refinery/namespace/admin/plural_name_spec.rb.erb +1 -1
  107. data/lib/generators/refinery/engine/templates/spec/spec_helper.rb +25 -49
  108. data/lib/generators/refinery/form/form_generator.rb +1 -13
  109. data/lib/generators/refinery/form/templates/app/models/refinery/namespace/singular_name.rb.erb +0 -4
  110. data/lib/generators/refinery/form/templates/app/views/refinery/namespace/admin/plural_name/_records.html.erb +2 -2
  111. data/lib/generators/refinery/form/templates/app/views/refinery/namespace/admin/plural_name/spam.html.erb +7 -6
  112. data/lib/generators/refinery/form/templates/config/locales/nl.yml +29 -29
  113. data/lib/generators/refinery/form/templates/config/locales/tr.yml +78 -0
  114. data/lib/generators/refinery/form/templates/config/routes.rb.erb +1 -1
  115. data/lib/generators/refinery/form/templates/db/migrate/1_create_plural_name.rb.erb +2 -6
  116. data/lib/generators/refinery/form/templates/db/seeds.rb.erb +1 -1
  117. data/lib/generators/refinery/form/templates/lib/refinery/plural_name/engine.rb.erb +1 -1
  118. data/lib/generators/refinery/form/templates/refinerycms-plural_name.gemspec +2 -5
  119. data/lib/refinery.rb +191 -0
  120. data/lib/refinery/admin/base_controller.rb +27 -16
  121. data/lib/refinery/application_controller.rb +15 -47
  122. data/lib/refinery/cli.rb +48 -27
  123. data/lib/refinery/core.rb +7 -183
  124. data/lib/refinery/core/configuration.rb +17 -9
  125. data/lib/refinery/core/engine.rb +11 -47
  126. data/lib/refinery/crud.rb +81 -66
  127. data/lib/refinery/engine.rb +52 -55
  128. data/lib/refinery/ext/action_view/helpers/form_builder.rb +2 -0
  129. data/lib/refinery/extension_generation.rb +208 -110
  130. data/lib/refinery/menu.rb +16 -7
  131. data/lib/refinery/menu_item.rb +56 -54
  132. data/lib/refinery/plugin.rb +11 -3
  133. data/lib/refinery/plugins.rb +14 -1
  134. data/lib/refinery/version.rb +3 -3
  135. data/refinerycms-core.gemspec +11 -10
  136. data/spec/controllers/refinery/admin/dummy_controller_spec.rb +57 -0
  137. data/spec/controllers/refinery/admin/refinery_core_controller_spec.rb +3 -4
  138. data/spec/controllers/refinery/sitemap_controller_spec.rb +1 -14
  139. data/spec/{requests → features}/refinery/admin/custom_assets_spec.rb +1 -1
  140. data/spec/{requests → features}/refinery/admin/dialogs_spec.rb +1 -1
  141. data/spec/features/refinery/admin/xhr_paging_spec.rb +55 -0
  142. data/spec/features/refinery/application_layout_spec.rb +19 -0
  143. data/spec/features/refinery/core_spec.rb +14 -0
  144. data/spec/{requests → features}/refinery/site_bar_spec.rb +1 -1
  145. data/spec/helpers/refinery/meta_helper_spec.rb +25 -0
  146. data/spec/lib/generators/refinery/cms/cms_generator_spec.rb +61 -0
  147. data/spec/lib/generators/refinery/engine/engine_generator_multiple_resources_spec.rb +28 -1
  148. data/spec/lib/generators/refinery/engine/engine_generator_sanity_check_spec.rb +7 -7
  149. data/spec/lib/generators/refinery/engine/engine_generator_spec.rb +69 -8
  150. data/spec/lib/generators/refinery/engine/engine_generator_with_i18n_spec.rb +0 -2
  151. data/spec/lib/generators/refinery/form/form_generator_spec.rb +9 -1
  152. data/spec/lib/refinery/application_controller_spec.rb +48 -63
  153. data/spec/lib/refinery/cli_spec.rb +136 -0
  154. data/spec/lib/refinery/core/configuration_spec.rb +17 -0
  155. data/spec/lib/refinery/core_spec.rb +19 -13
  156. data/spec/lib/refinery/crud_spec.rb +0 -4
  157. data/spec/lib/refinery/menu_spec.rb +16 -26
  158. data/spec/support/refinery.rb +6 -1
  159. data/{app → vendor}/assets/javascripts/jquery/GPL-LICENSE.txt +0 -0
  160. data/{app → vendor}/assets/javascripts/jquery/MIT-LICENSE.txt +0 -0
  161. data/vendor/assets/javascripts/jquery/jquery.browser.js +49 -0
  162. data/{app → vendor}/assets/javascripts/jquery/jquery.html5-placeholder-shim.js +0 -0
  163. data/{app → vendor}/assets/javascripts/jquery/jquery.jcarousel.js +0 -0
  164. data/{app → vendor}/assets/javascripts/jquery/jquery.textTruncate.js +0 -0
  165. data/{app → vendor}/assets/javascripts/jquery/jquery.timers.js +0 -0
  166. data/{app → vendor}/assets/javascripts/modernizr-min.js +0 -0
  167. metadata +231 -78
  168. data/app/assets/images/refinery/resolve_digital_footer_logo.png +0 -0
  169. data/app/assets/javascripts/dd_belatedpng.js +0 -13
  170. data/app/assets/javascripts/jquery/jquery.corner.js +0 -345
  171. data/app/assets/stylesheets/application.css.scss +0 -55
  172. data/app/assets/stylesheets/home.css.scss +0 -3
  173. data/app/views/refinery/_ie6check.html.erb +0 -63
  174. data/app/views/refinery/_menu.html.erb +0 -20
  175. data/app/views/refinery/_menu_branch.html.erb +0 -19
  176. data/lib/generators/refinery/engine/templates/Guardfile +0 -27
  177. data/lib/generators/refinery/engine/templates/app/views/refinery/namespace/admin/plural_name/_locale_picker.html.erb +0 -11
  178. data/lib/refinery/catch_all_routes.rb +0 -3
  179. data/lib/tasks/yard.rake +0 -30
  180. data/spec/requests/refinery/admin/controller_restriction_spec.rb +0 -27
  181. data/spec/requests/refinery/search_spec.rb +0 -71
@@ -1,3 +1,5 @@
1
+ require 'action_view/helpers'
2
+
1
3
  ActionView::Helpers::FormBuilder.module_eval do
2
4
 
3
5
  def required_label(method, options = {})
@@ -8,6 +8,7 @@ module Refinery
8
8
  class_option :namespace, :type => :string, :default => nil, :banner => 'NAMESPACE', :required => false
9
9
  class_option :extension, :type => :string, :default => nil, :banner => 'ENGINE', :required => false
10
10
  class_option :i18n, :type => :array, :default => [], :required => false, :banner => "field field", :desc => 'Indicates generated fields'
11
+ class_option :install, :type => :boolean, :default => false, :required => false, :banner => nil, :desc => 'Bundles and runs the generated generator, rake db:migrate, rake db:seed for you'
11
12
 
12
13
  remove_class_option :skip_namespace
13
14
  end
@@ -18,7 +19,13 @@ module Refinery
18
19
  # Use exactly what the user requested, not a pluralised version.
19
20
  options[:namespace].to_s.camelize
20
21
  else
21
- class_name.pluralize
22
+ # If the user has passed an engine, we want to generate it inside of
23
+ # that extension.
24
+ if options[:extension].present?
25
+ options[:extension].to_s.camelize
26
+ else
27
+ class_name.pluralize
28
+ end
22
29
  end
23
30
  end
24
31
 
@@ -83,7 +90,7 @@ module Refinery
83
90
  end
84
91
  end
85
92
 
86
- protected
93
+ protected
87
94
 
88
95
  def append_extension_to_gemfile!
89
96
  unless Rails.env.test? || (self.behavior != :revoke && extension_in_gemfile?)
@@ -103,6 +110,24 @@ module Refinery
103
110
  end
104
111
  end
105
112
 
113
+ def default_generate!
114
+ sanity_check!
115
+
116
+ evaluate_templates!
117
+
118
+ unless options[:pretend]
119
+ merge_existing_files! if existing_extension?
120
+
121
+ copy_or_merge_seeds!
122
+
123
+ append_extension_to_gemfile!
124
+ end
125
+
126
+ install! if options[:install]
127
+
128
+ finalize_extension!
129
+ end
130
+
106
131
  def destination_pathname
107
132
  @destination_pathname ||= Pathname.new(self.destination_root.to_s)
108
133
  end
@@ -112,44 +137,20 @@ module Refinery
112
137
  end
113
138
 
114
139
  def extension_path_for(path, extension, apply_tmp = true)
115
- path = extension_pathname.join(path.to_s.gsub(%r{#{source_pathname}/?}, '')).to_s
116
-
117
- path.gsub!('extension_plural_name', extension_plural_name)
118
- path.gsub!('plural_name', plural_name)
119
- path.gsub!('singular_name', singular_name)
120
- path.gsub!('namespace', namespacing.underscore)
140
+ path = extension_pathname.join path.sub(%r{#{source_pathname}/?}, '')
141
+ path = substitute_path_placeholders path
121
142
 
122
143
  if options[:namespace].present? || options[:extension].present?
123
- # Increment the migration file leading number
124
- # Only relevant for nested or namespaced extensions, where a previous migration exists
125
- if %r{/migrate/\d+.*\.rb.erb\z} === path
126
- if last_migration = Dir["#{destination_pathname.join(path.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR), '*.rb')}"].sort.last
127
- path.gsub!(%r{\d+_}) { |m| "#{last_migration.match(%r{migrate/(\d+)_})[1].to_i + 1}_" }
128
- end
129
- end
144
+ path = increment_migration_timestamp(path)
130
145
 
131
146
  # Detect whether this is a special file that needs to get merged not overwritten.
132
147
  # This is important only when nesting extensions.
133
148
  # Routes and #{gem_name}\.rb have an .erb extension as path points to the generator template
134
149
  # We have to exclude it when checking if the file already exists and include it in the regexps
135
- if extension.present? && File.exist?(path.gsub(/\.erb$/, ""))
136
- if %r{/locales/.*\.yml$} === path ||
137
- %r{/routes\.rb\.erb$} === path ||
138
- %r{/#{gem_name}\.rb\.erb$} === path
139
- # put new translations into a tmp directory
140
- if apply_tmp
141
- path = path.split(File::SEPARATOR).insert(-2, "tmp").
142
- join(File::SEPARATOR)
143
- end
144
- elsif %r{/readme.md$} === path || %r{/#{plural_name}.rb$} === path
145
- path = nil
146
- end
147
- elsif extension.present? and path =~ /lib\/#{plural_name}.rb$/
148
- path = nil
149
- end
150
+ path = extension_path_for_nested_extension(path, apply_tmp) if extension.present?
150
151
  end
151
152
 
152
- path.present? ? Pathname.new(path) : path
153
+ path
153
154
  end
154
155
 
155
156
  def erase_destination!
@@ -160,18 +161,12 @@ module Refinery
160
161
  end
161
162
 
162
163
  def evaluate_templates!
163
- Pathname.glob(source_pathname.join('**', '**')).reject{|f|
164
- reject_template?(f)
165
- }.sort.each do |path|
166
- if (template_path = extension_path_for(path, extension_name)).present?
167
- next if path.to_s =~ /seeds.rb.erb/
168
-
169
- unless path.to_s =~ /views/
170
- template_path = template_path.to_s.sub(".erb", "")
171
- end
164
+ viable_templates.each do |source_path, destination_path|
165
+ next if /seeds.rb.erb/ === source_path.to_s
172
166
 
173
- template path, template_path
174
- end
167
+ destination_path.sub!('.erb', '') if source_path.to_s !~ /views/
168
+
169
+ template source_path, destination_path
175
170
  end
176
171
  end
177
172
 
@@ -189,8 +184,8 @@ module Refinery
189
184
  end
190
185
 
191
186
  def finalize_extension!
192
- if self.behavior != :revoke and !self.options['pretend']
193
- puts_instructions!
187
+ if self.behavior != :revoke && !self.options['pretend']
188
+ instruct_user!
194
189
  else
195
190
  erase_destination!
196
191
  end
@@ -210,79 +205,47 @@ module Refinery
210
205
  raise "You must override the method 'generator_command' in your generator."
211
206
  end
212
207
 
213
- def merge_locales!
214
- if existing_extension?
215
- # go through all of the temporary files and merge what we need into the current files.
216
- tmp_directories = []
217
- Dir.glob(source_pathname.join("{config/locales/*.yml,config/routes.rb.erb,lib/refinerycms-extension_plural_name.rb.erb}"), File::FNM_DOTMATCH).sort.each do |path|
218
- # get the path to the current tmp file.
219
- # Both the new and current paths need to strip the .erb portion from the generator template
220
- new_file_path = Pathname.new extension_path_for(path, extension_name).to_s.gsub(/\.erb$/, "")
221
- tmp_directories << Pathname.new(new_file_path.to_s.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR)) # save for later
222
- # get the path to the existing file and perform a deep hash merge.
223
- current_path = Pathname.new extension_path_for(path, extension_name, false).to_s.gsub(/\.erb$/, "")
224
- new_contents = nil
225
-
226
- if File.exist?(new_file_path) && %r{.yml$} === new_file_path.to_s
227
- # merge translation files together.
228
- new_contents = YAML::load(new_file_path.read).deep_merge(
229
- YAML::load(current_path.read)
230
- ).to_yaml.gsub(%r{^---\n}, '')
231
- elsif %r{/routes.rb$} === new_file_path.to_s
232
- # append any routes from the new file to the current one.
233
- routes_file = [(file_parts = current_path.read.to_s.split("\n")).first]
234
- routes_file += file_parts[1..-2]
235
- routes_file += new_file_path.read.to_s.split("\n")[1..-2]
236
- routes_file << file_parts.last
237
- new_contents = routes_file.join("\n")
238
- elsif %r{/#{gem_name}.rb$} === new_file_path.to_s
239
- new_contents = current_path.read + new_file_path.read
240
- end
241
- # write to current file the merged results.
242
- current_path.open('w+') { |file| file.puts new_contents } if new_contents
243
- end
208
+ def install!
209
+ run "bundle install"
210
+ run "rails generate refinery:#{extension_plural_name}"
211
+ run "rake db:migrate"
212
+ run "rake db:seed"
213
+ end
244
214
 
245
- tmp_directories.uniq.each{|dir| remove_dir(dir) if dir && dir.exist?}
215
+ def merge_existing_files!
216
+ # go through all of the temporary files and merge what we need into the current files.
217
+ tmp_directories = []
218
+ globs = %w[config/locales/*.yml config/routes.rb.erb lib/refinerycms-extension_plural_name.rb.erb]
219
+ Pathname.glob(source_pathname.join("{#{globs.join(',')}}"), File::FNM_DOTMATCH).each do |path|
220
+ # get the path to the current tmp file.
221
+ # Both the new and current paths need to strip the .erb portion from the generator template
222
+ new_file_path = extension_path_for(path, extension_name).sub(/\.erb$/, '')
223
+ tmp_directories << new_file_path.split.first
224
+ current_path = extension_path_for(path, extension_name, false).sub(/\.erb$/, '')
225
+
226
+ FileMerger.new(self, current_path, new_file_path, :to => current_path, :mode => 'w+').call
246
227
  end
228
+
229
+ tmp_directories.uniq.each(&:rmtree)
247
230
  end
248
231
 
249
232
  def copy_or_merge_seeds!
250
- source_seed_file = source_pathname.join("db/seeds.rb.erb")
251
- destination_seed_file = destination_pathname.join(
252
- extension_path_for(
253
- source_seed_file.to_s.sub(".erb", ""), extension_name
254
- )
255
- )
256
-
257
- if existing_extension?
258
- # create temp seeds file
259
- temp_seed_file = destination_pathname.join(
260
- extension_path_for("tmp/seeds.rb", extension_name)
261
- )
262
-
263
- # copy/evaluate seeds template to temp file
264
- template source_seed_file, temp_seed_file, :verbose => false
265
-
266
- # append temp seeds file content to extension seeds file
267
- destination_seed_file.open('a+') { |file|
268
- file.puts temp_seed_file.read.to_s
269
- }
270
-
271
- # remove temp file
272
- FileUtils.rm_rf temp_seed_file
273
- else
274
- template source_seed_file, destination_seed_file
275
- end
233
+ FileMerger.new(self, source_seed_file, destination_seed_file).call
276
234
  end
277
235
 
278
- def puts_instructions!
236
+ def instruct_user!
279
237
  unless Rails.env.test?
280
238
  puts "------------------------"
281
- puts "Now run:"
282
- puts "bundle install"
283
- puts "rails generate refinery:#{extension_plural_name}"
284
- puts "rake db:migrate"
285
- puts "rake db:seed"
239
+ if options[:install]
240
+ puts "Your extension has been generated and installed."
241
+ else
242
+ puts "Now run:"
243
+ puts "bundle install"
244
+ puts "rails generate refinery:#{extension_plural_name}"
245
+ puts "rake db:migrate"
246
+ puts "rake db:seed"
247
+ end
248
+ puts "Please restart your rails server."
286
249
  puts "------------------------"
287
250
  end
288
251
  end
@@ -296,10 +259,47 @@ module Refinery
296
259
  end
297
260
 
298
261
  def sanity_check!
262
+ prevent_clashes!
263
+ prevent_uncountability!
264
+ prevent_empty_attributes!
265
+ prevent_invalid_extension!
266
+ end
267
+
268
+ def source_pathname
269
+ @source_pathname ||= Pathname.new(self.class.source_root.to_s)
270
+ end
271
+
272
+ private
273
+ def extension_path_for_nested_extension(path, apply_tmp)
274
+ return nil if !path.sub(/\.erb$/, '').file? &&
275
+ %r{readme.md|(lib/)?#{plural_name}.rb$} === path.to_s
276
+
277
+ if apply_tmp && %r{(locales/.*\.yml)|((config/routes|#{gem_name})\.rb\.erb)$} === path.to_s
278
+ path = path.dirname + 'tmp' + path.basename
279
+ end
280
+
281
+ path
282
+ end
283
+
284
+ def increment_migration_timestamp(path)
285
+ # Increment the migration file leading number
286
+ # Only relevant for nested or namespaced extensions, where a previous migration exists
287
+ return path unless %r{/migrate/\d+.*\.rb.erb\z} === path.to_s && last_migration_file(path)
288
+
289
+ path.sub(%r{\d+_}) { |m| "#{last_migration_file(path).match(%r{migrate/(\d+)_})[1].to_i + 1}_" }
290
+ end
291
+
292
+ def last_migration_file(path)
293
+ Dir[destination_pathname.join(path.dirname + '*.rb')].sort.last
294
+ end
295
+
296
+ def prevent_clashes!
299
297
  if clash_keywords.member?(singular_name.downcase)
300
298
  exit_with_message!("Please choose a different name. The generated code would fail for class '#{singular_name}' as it conflicts with a reserved keyword.")
301
299
  end
300
+ end
302
301
 
302
+ def prevent_uncountability!
303
303
  if singular_name == plural_name
304
304
  message = if singular_name.singularize == singular_name
305
305
  "The extension name you specified will not work as the singular name is equal to the plural name."
@@ -308,21 +308,119 @@ module Refinery
308
308
  end
309
309
  exit_with_message! message
310
310
  end
311
+ end
311
312
 
313
+ def prevent_empty_attributes!
312
314
  if attributes.empty? && self.behavior != :revoke
313
315
  exit_with_message! "You must specify a name and at least one field." \
314
316
  "\nFor help, run: #{generator_command}"
315
317
  end
318
+ end
316
319
 
320
+ def prevent_invalid_extension!
317
321
  if options[:extension].present? && !extension_pathname.directory?
318
322
  exit_with_message! "You can't use '--extension #{options[:extension]}' option because" \
319
323
  " extension with name #{options[:extension]} doesn't exist."
320
324
  end
321
325
  end
322
326
 
323
- def source_pathname
324
- @source_pathname ||= Pathname.new(self.class.source_root.to_s)
327
+ def source_seed_file
328
+ source_pathname.join 'db', 'seeds.rb.erb'
329
+ end
330
+
331
+ def destination_seed_file
332
+ destination_pathname.join extension_path_for(source_seed_file.sub('.erb', ''), extension_name)
333
+ end
334
+
335
+ def substitute_path_placeholders(path)
336
+ Pathname.new path.to_s.gsub('extension_plural_name', extension_plural_name).
337
+ gsub('plural_name', plural_name).
338
+ gsub('singular_name', singular_name).
339
+ gsub('namespace', namespacing.underscore)
340
+ end
341
+
342
+ def viable_templates
343
+ @viable_templates ||= begin
344
+ all_templates.reject(&method(:reject_template?)).inject({}) do |hash, path|
345
+ if (destination_path = extension_path_for(path, extension_name)).present?
346
+ hash[path.to_s] = destination_path.to_s
347
+ end
348
+
349
+ hash
350
+ end
351
+ end
352
+ end
353
+
354
+ def all_templates
355
+ Pathname.glob source_pathname.join('**', '**')
356
+ end
357
+
358
+ class FileMerger
359
+ def initialize(templater, source, destination, options = {})
360
+ @templater = templater
361
+ @source = source
362
+ @destination = destination
363
+ @options = {:to => @destination, :mode => 'a+'}.merge(options)
364
+ end
365
+
366
+ def call
367
+ if %r{\.erb$} === @source.basename.to_s
368
+ templated_merge!
369
+ else
370
+ merge!
371
+ end
372
+ end
373
+
374
+ def contents
375
+ merged_file_contents
376
+ end
377
+
378
+ private
379
+ def merge!(contents = merged_file_contents)
380
+ @options[:to].open(@options[:mode]) { |file| file.puts contents }
381
+ end
382
+
383
+ def merged_file_contents
384
+ case @destination.to_s
385
+ # merge translation files together.
386
+ when %r{.yml$} then merge_yaml
387
+ # append any routes from the new file to the current one.
388
+ when %r{/routes.rb$} then merge_rb
389
+ # simply append the file contents
390
+ else @source.read + @destination.read
391
+ end
392
+ end
393
+
394
+ def templated_merge!
395
+ Dir.mktmpdir do |tmp|
396
+ tmp = Pathname.new(tmp)
397
+ @templater.template @source, tmp.join(@source.basename), :verbose => false
398
+ merge! tmp.join(@source.basename).read.to_s
399
+ end
400
+ end
401
+
402
+ def merge_rb
403
+ (source_lines[0..-2] + destination_lines[1..-2] + [source_lines.last]).join "\n"
404
+ end
405
+
406
+ def merge_yaml
407
+ YAML::load(@destination.read).deep_merge(YAML::load(@source.read)).
408
+ to_yaml.gsub(%r{^---\n}, '')
409
+ end
410
+
411
+ def source_lines
412
+ @source_lines ||= read_lines @source
413
+ end
414
+
415
+ def destination_lines
416
+ @destination_lines ||= read_lines @destination
417
+ end
418
+
419
+ def read_lines(file)
420
+ file.read.to_s.split "\n"
421
+ end
325
422
  end
423
+ private_constant :FileMerger
326
424
 
327
425
  end
328
426
  end
data/lib/refinery/menu.rb CHANGED
@@ -2,10 +2,14 @@ module Refinery
2
2
  class Menu
3
3
 
4
4
  def initialize(objects = nil)
5
- objects.each do |item|
5
+ append(objects)
6
+ end
7
+
8
+ def append(objects)
9
+ Array(objects).each do |item|
6
10
  item = item.to_refinery_menu_item if item.respond_to?(:to_refinery_menu_item)
7
- items << MenuItem.new(item.merge(:menu => self))
8
- end if objects
11
+ items << MenuItem.new(self, item)
12
+ end
9
13
  end
10
14
 
11
15
  attr_accessor :items
@@ -15,14 +19,19 @@ module Refinery
15
19
  end
16
20
 
17
21
  def roots
18
- @roots ||= items.select {|item| item.parent_id.nil?}
22
+ @roots ||= select {|item| item.orphan? && item.depth == minimum_depth }
19
23
  end
20
24
 
21
25
  def to_s
22
- items.map(&:title).join(' ')
26
+ map(&:title).join(' ')
27
+ end
28
+
29
+ delegate :inspect, :map, :select, :detect, :first, :last, :length, :size, :to => :items
30
+
31
+ protected
32
+ def minimum_depth
33
+ map(&:depth).min
23
34
  end
24
35
 
25
- # The delegation is specified so crazily so that it works on 1.8.x and 1.9.x
26
- delegate *((Array.instance_methods - Object.instance_methods) << {:to => :items})
27
36
  end
28
37
  end