refinerycms-generators 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/features/engine_generator.feature +27 -0
  2. data/features/step_definitions/engine_generator_steps.rb +19 -0
  3. data/features/step_definitions/generator_steps.rb +7 -0
  4. data/features/step_definitions/support/paths.rb +14 -0
  5. data/lib/gemspec.rb +29 -0
  6. data/lib/generators/refinery_engine/USAGE +23 -0
  7. data/lib/generators/refinery_engine/refinery_engine_generator.rb +140 -0
  8. data/lib/generators/refinery_engine/templates/app/controllers/admin/plural_name_controller.rb +8 -0
  9. data/lib/generators/refinery_engine/templates/app/controllers/plural_name_controller.rb +30 -0
  10. data/lib/generators/refinery_engine/templates/app/models/singular_name.rb +21 -0
  11. data/lib/generators/refinery_engine/templates/app/views/admin/plural_name/_form.html.erb +36 -0
  12. data/lib/generators/refinery_engine/templates/app/views/admin/plural_name/_singular_name.html.erb +18 -0
  13. data/lib/generators/refinery_engine/templates/app/views/admin/plural_name/_sortable_list.html.erb +4 -0
  14. data/lib/generators/refinery_engine/templates/app/views/admin/plural_name/edit.html.erb +1 -0
  15. data/lib/generators/refinery_engine/templates/app/views/admin/plural_name/index.html.erb +56 -0
  16. data/lib/generators/refinery_engine/templates/app/views/admin/plural_name/new.html.erb +1 -0
  17. data/lib/generators/refinery_engine/templates/app/views/plural_name/index.html.erb +11 -0
  18. data/lib/generators/refinery_engine/templates/app/views/plural_name/show.html.erb +33 -0
  19. data/lib/generators/refinery_engine/templates/config/locales/en.yml +24 -0
  20. data/lib/generators/refinery_engine/templates/config/locales/lolcat.yml +24 -0
  21. data/lib/generators/refinery_engine/templates/config/locales/nb.yml +20 -0
  22. data/lib/generators/refinery_engine/templates/config/locales/nl.yml +20 -0
  23. data/lib/generators/refinery_engine/templates/config/routes.rb +11 -0
  24. data/lib/generators/refinery_engine/templates/db/migrate/create_plural_name.rb +33 -0
  25. data/lib/generators/refinery_engine/templates/db/seeds/plural_name.rb +17 -0
  26. data/lib/generators/refinery_engine/templates/features/manage_plural_name.feature +63 -0
  27. data/lib/generators/refinery_engine/templates/features/step_definitions/singular_name_steps.rb +16 -0
  28. data/lib/generators/refinery_engine/templates/features/support/paths.rb +17 -0
  29. data/lib/generators/refinery_engine/templates/lib/generators/refinerycms_plural_name_generator.rb +6 -0
  30. data/lib/generators/refinery_engine/templates/lib/refinerycms-plural_name.rb +20 -0
  31. data/lib/generators/refinery_engine/templates/lib/tasks/plural_name.rake +13 -0
  32. data/lib/generators/refinery_engine/templates/readme.md +10 -0
  33. data/lib/generators/refinery_engine/templates/refinerycms-plural_name.gemspec +10 -0
  34. data/lib/generators/refinery_engine/templates/spec/models/singular_name_spec.rb +32 -0
  35. data/lib/refinery/generators.rb +62 -0
  36. data/lib/refinerycms-generators.rb +43 -0
  37. data/readme.md +50 -0
  38. data/refinerycms-generators.gemspec +85 -0
  39. metadata +115 -0
@@ -0,0 +1,27 @@
1
+ @refinerycms @engine-generator @generator
2
+ Feature: Engine generation
3
+ In order to create my own engine
4
+ As a refinery user
5
+ I want to generate a basic engine directory structure
6
+
7
+ Scenario: Generating an engine with a name
8
+ Given I have a refinery application
9
+ When I generate an engine with the arguments of "cucumber_product_test title:string description:text image:image brochure:resource"
10
+ Then I should have a directory "vendor/engines/cucumber_product_tests"
11
+ And I should have a directory "vendor/engines/cucumber_product_tests/app"
12
+ And I should have a directory "vendor/engines/cucumber_product_tests/lib"
13
+ And I should have a directory "vendor/engines/cucumber_product_tests/config"
14
+ And I should have a file "vendor/engines/cucumber_product_tests/app/controllers/admin/cucumber_product_tests_controller.rb"
15
+ And I should have a file "vendor/engines/cucumber_product_tests/app/controllers/cucumber_product_tests_controller.rb"
16
+ And I should have a file "vendor/engines/cucumber_product_tests/app/models/cucumber_product_test.rb"
17
+ And I should have a file "vendor/engines/cucumber_product_tests/config/routes.rb"
18
+ And I should have a file "vendor/engines/cucumber_product_tests/config/locales/en.yml"
19
+ And I should have a file "vendor/engines/cucumber_product_tests/lib/refinerycms-cucumber_product_tests.rb"
20
+ And I should have a file "vendor/engines/cucumber_product_tests/app/views/admin/cucumber_product_tests/_form.html.erb"
21
+ And I should have a file "vendor/engines/cucumber_product_tests/app/views/admin/cucumber_product_tests/_sortable_list.html.erb"
22
+ And I should have a file "vendor/engines/cucumber_product_tests/app/views/admin/cucumber_product_tests/edit.html.erb"
23
+ And I should have a file "vendor/engines/cucumber_product_tests/app/views/admin/cucumber_product_tests/index.html.erb"
24
+ And I should have a file "vendor/engines/cucumber_product_tests/app/views/admin/cucumber_product_tests/new.html.erb"
25
+ And I should have a file "vendor/engines/cucumber_product_tests/app/views/admin/cucumber_product_tests/_cucumber_product_test.html.erb"
26
+ And I should have a file "vendor/engines/cucumber_product_tests/app/views/cucumber_product_tests/index.html.erb"
27
+ And I should have a file "vendor/engines/cucumber_product_tests/app/views/cucumber_product_tests/show.html.erb"
@@ -0,0 +1,19 @@
1
+ require File.expand_path("../../../lib/generators/refinery_engine/refinery_engine_generator", __FILE__)
2
+
3
+ Before do
4
+ @engine_generator_root = File.expand_path('../../../', __FILE__)
5
+ @tmp_refinery_app_name = "tmp_refinery_app"
6
+ @tmp_refinery_app_root = File.join(@engine_generator_root, @tmp_refinery_app_name)
7
+ @app_root = @tmp_refinery_app_root
8
+ end
9
+
10
+ After do
11
+ FileUtils.rm_rf(@tmp_refinery_app_root)
12
+ end
13
+
14
+ When /^I generate an engine with the arguments of "([^"]*)"$/ do |arguments|
15
+ generator = RefineryEngineGenerator.new(arguments.split(" "))
16
+ generator.destination_root = @app_root
17
+ generator.options = {:quiet => true}
18
+ generator.generate
19
+ end
@@ -0,0 +1,7 @@
1
+ Given /^I have a refinery application$/ do
2
+ FileUtils.mkdir(File.join(@app_root))
3
+ end
4
+
5
+ Then /^I should have a (?:directory|file) "([^"]*)"$/ do |name|
6
+ File.exist?(File.join(@tmp_refinery_app_root, name)).should be_true
7
+ end
@@ -0,0 +1,14 @@
1
+ module NavigationHelpers
2
+ module Refinery
3
+ module Generators
4
+ def path_to(page_name)
5
+ # no paths
6
+ nil
7
+ #case page_name
8
+ #else
9
+ # nil
10
+ #end
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/gemspec.rb ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ version = '0.9.9'
3
+ raise "Could not get version so gemspec can not be built" if version.nil?
4
+ files = Dir.glob("**/*").flatten.reject do |file|
5
+ file =~ /\.gem$/
6
+ end
7
+
8
+ gemspec = <<EOF
9
+ Gem::Specification.new do |s|
10
+ s.name = %q{refinerycms-generators}
11
+ s.version = %q{#{version}}
12
+ s.date = %q{#{Time.now.strftime('%Y-%m-%d')}}
13
+ s.summary = %q{Core generators for the Refinery CMS project.}
14
+ s.description = %q{Core generators for Refinery CMS including refinery_engine.}
15
+ s.homepage = %q{http://refinerycms.com}
16
+ s.email = %q{info@refinerycms.com}
17
+ s.authors = ["Resolve Digital"]
18
+ s.require_paths = %w(lib)
19
+
20
+ s.add_dependency 'refinerycms', '>= 0.9.9'
21
+
22
+ s.files = [
23
+ '#{files.join("',\n '")}'
24
+ ]
25
+ s.require_path = 'lib'
26
+ end
27
+ EOF
28
+
29
+ File.open(File.expand_path("../../refinerycms-generators.gemspec", __FILE__), 'w').puts(gemspec)
@@ -0,0 +1,23 @@
1
+ Description:
2
+ Generates a custom plugin for Refinery automatically. It works very similar
3
+ to the Rails scaffold generator.
4
+
5
+ A generated plugin gives you all the basic files needed to manage the model
6
+ the plugin will be for.
7
+
8
+ The first attribute should always be the one which is the title or name of
9
+ the model.
10
+
11
+ There must be at least one attribute.
12
+
13
+ Additional Supported Field Types
14
+
15
+ All field types that are supported by the Rails Scaffold generator are supported with the addition
16
+ of these Refinery specific ones:
17
+
18
+ text - text area with a visual editor
19
+ image - link to an image picker dialogue
20
+ resource - link to a resource picker dialogue
21
+
22
+ Example:
23
+ rails generate refinery_engine product title:string description:text image:image brochure:resource
@@ -0,0 +1,140 @@
1
+ require 'rails/generators/migration'
2
+ require 'yaml'
3
+ require 'pathname'
4
+
5
+ class RefineryEngineGenerator < Rails::Generators::NamedBase
6
+
7
+ include Rails::Generators::Migration
8
+
9
+ source_root Pathname.new(File.expand_path('../templates', __FILE__))
10
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
11
+
12
+ def generate
13
+ unless attributes.empty? and self.behavior != :revoke
14
+ if (engine = attributes.detect{|a| a.type.to_s == 'engine'}).present? and attributes.reject!{|a| a.type.to_s == 'engine'}.present?
15
+ engine = engine.name.pluralize
16
+ end
17
+
18
+ Pathname.glob(Pathname.new(self.class.source_root).join('**', '**')).reject{|f| f.directory?}.sort.each do |path|
19
+ unless (engine_path = engine_path_for(path, engine)).nil?
20
+ template path, engine_path
21
+ end
22
+ end
23
+
24
+ if engine.present?
25
+ # go through all of the temporary files and merge what we need into the current files.
26
+ tmp_directories = []
27
+ Dir.glob(File.expand_path('../templates/{config/locales/*.yml,config/routes.rb,features/support/paths.rb}', __FILE__), File::FNM_DOTMATCH).sort.each do |path|
28
+ # get the path to the current tmp file.
29
+ new_file_path = Rails.root.join(engine_path_for(path, engine))
30
+ tmp_directories << Pathname.new(new_file_path.to_s.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR)) # save for later
31
+
32
+ # get the path to the existing file and perform a deep hash merge.
33
+ current_path = Pathname.new(new_file_path.to_s.split(File::SEPARATOR).reject{|f| f == 'tmp'}.join(File::SEPARATOR))
34
+ new_contents = nil
35
+ if new_file_path.to_s =~ %r{.yml$}
36
+ # merge translation files together.
37
+ new_contents = YAML::load(new_file_path.read).deep_merge(YAML::load(current_path.read)).to_yaml
38
+ elsif new_file_path.to_s =~ %r{/routes.rb$}
39
+ # append any routes from the new file to the current one.
40
+ routes_file = [(file_parts = current_path.read.to_s.split("\n")).first]
41
+ routes_file += file_parts[1..-2]
42
+ routes_file += new_file_path.read.to_s.split("\n")[1..-2]
43
+ routes_file << file_parts.last
44
+ new_contents = routes_file.join("\n")
45
+ elsif new_file_path.to_s =~ %r{/features/support.*paths.rb$}
46
+ # ugh, please FIXME -- requires deep and intimate knowledge of the contents.
47
+ paths_file = (file_parts = current_path.read.to_s.split("\n"))[0..4]
48
+ paths_file << file_parts[5..-8].join("\n")
49
+
50
+ # get the parts of the new file that are relevant
51
+ new_file_parts = new_file_path.read.split("\n")
52
+ paths_file << new_file_parts[5..-4].join("\n")
53
+ paths_file << file_parts[-3..-1]
54
+
55
+ # join it all together
56
+ new_contents = paths_file.join("\n")
57
+ end
58
+ # write to current file the merged results.
59
+ current_path.open('w+') { |f| f.puts new_contents } unless new_contents.nil?
60
+ end
61
+
62
+ tmp_directories.uniq.each{|d| d.rmtree unless d.nil? or !d.exist?}
63
+ end
64
+
65
+ # Update the gem file
66
+ if self.behavior != :revoke and !self.options['pretend']
67
+ unless Rails.env.test?
68
+ Rails.root.join('Gemfile').open('a') do |f|
69
+ f.write "\ngem 'refinerycms-#{plural_name}', '1.0', :path => 'vendor/engines'"
70
+ end unless engine.present?
71
+
72
+ puts "------------------------"
73
+ puts "Now run:"
74
+ puts "bundle install"
75
+ unless engine.present?
76
+ puts "rails generate refinerycms_#{plural_name}"
77
+ else
78
+ puts "rails generate refinerycms_#{engine} #{plural_name}"
79
+ end
80
+ puts "rake db:migrate"
81
+ puts "------------------------"
82
+ end
83
+ elsif self.behavior == :revoke
84
+ lines = Rails.root.join('Gemfile').open('r').read.split("\n")
85
+ Rails.root.join('Gemfile').open('w').puts(lines.reject {|l|
86
+ l =~ %r{refinerycms-#{plural_name}}
87
+ }.join("\n"))
88
+
89
+ migration_files = Dir.glob(File.expand_path('../templates/db/migrate/*.rb', __FILE__)).sort.collect{|m|
90
+ m.gsub('plural_name', plural_name).gsub('singular_name', singular_name).split(File::SEPARATOR).last.split('_')[1..-1].join('_')
91
+ }
92
+ if (migration_paths = Dir[Rails.root.join('db', 'migrate', "*#{migration_files.join(',')}")]).any?
93
+ puts ""
94
+ puts "I found #{'a ' unless migration_paths.many?}migration#{'s' if migration_paths.many?} at:"
95
+ puts migration_paths.join("\n")
96
+ puts ""
97
+ puts "Please ensure that you roll back these migrations if you used them (using rake db:rollback) and then run:"
98
+ puts "------------------------"
99
+ puts "rm #{migration_paths.join("\n rm ")}"
100
+ puts "rm #{Rails.root.join('db', 'seeds', "#{plural_name}.rb")}"
101
+ puts "------------------------"
102
+ puts "This will ensure that nothing gets left behind from this engine in your database."
103
+ puts "Note - be careful about rolling back if you have any migrations created after this one."
104
+ puts "This is because Rails rolls back only the last migration used each time you invoke rake db:rollback"
105
+ puts ""
106
+ end
107
+ end
108
+ else
109
+ puts "You must specify at least one field. For help: rails generate refinery_engine"
110
+ end
111
+ end
112
+
113
+ protected
114
+
115
+ def engine_path_for(path, engine)
116
+ engine_path = "vendor/engines/#{engine.present? ? engine : plural_name}/"
117
+ path = path.to_s.gsub(File.expand_path('../templates', __FILE__), engine_path)
118
+
119
+ path = path.gsub("plural_name", plural_name)
120
+ path = path.gsub("singular_name", singular_name)
121
+
122
+ # Detect whether this is a special file that needs to get merged not overwritten.
123
+ # This is important only when nesting engines.
124
+ if engine.present? and File.exist?(path)
125
+ path = if path =~ %r{/locales/.*\.yml$} or path =~ %r{/routes.rb$} or path =~ %r{/features/support/paths.rb$}
126
+ # put new translations into a tmp directory
127
+ path.split(File::SEPARATOR).insert(-2, "tmp").join(File::SEPARATOR)
128
+ elsif path =~ %r{/readme.md$} or path =~ %r{/#{plural_name}.rb$}
129
+ nil
130
+ else
131
+ path
132
+ end
133
+ elsif engine.present? and path =~ /lib\/#{plural_name}.rb$/
134
+ path = nil
135
+ end
136
+
137
+ path
138
+ end
139
+
140
+ end
@@ -0,0 +1,8 @@
1
+ class Admin::<%= class_name.pluralize %>Controller < Admin::BaseController
2
+
3
+ crudify :<%= singular_name %><% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? and title.name != 'title' %>,
4
+ :title_attribute => '<%= title.name %>'<% end %><% if plural_name == singular_name %>,
5
+ :redirect_to_url => :admin_<%= singular_name %>_index_url
6
+ <% end %>
7
+
8
+ end
@@ -0,0 +1,30 @@
1
+ class <%= class_name.pluralize %>Controller < ApplicationController
2
+
3
+ before_filter :find_all_<%= plural_name %>
4
+ before_filter :find_page
5
+
6
+ def index
7
+ # you can use meta fields from your model instead (e.g. browser_title)
8
+ # by swapping @page for @<%= singular_name %> in the line below:
9
+ present(@page)
10
+ end
11
+
12
+ def show
13
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
14
+
15
+ # you can use meta fields from your model instead (e.g. browser_title)
16
+ # by swapping @page for @<%= singular_name %> in the line below:
17
+ present(@page)
18
+ end
19
+
20
+ protected
21
+
22
+ def find_all_<%= plural_name %>
23
+ @<%= "all_" if plural_name == singular_name %><%= plural_name %> = <%= class_name %>.find(:all, :order => "position ASC")
24
+ end
25
+
26
+ def find_page
27
+ @page = Page.find_by_link_url("/<%= plural_name %>")
28
+ end
29
+
30
+ end
@@ -0,0 +1,21 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+
3
+ acts_as_indexed :fields => [:<%= attributes.collect{ |attribute| attribute.name if attribute.type.to_s =~ /string|text/ }.compact.uniq.join(", :") %>]
4
+ <% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>
5
+ validates :<%= title.name %>, :presence => true, :uniqueness => true
6
+ <% else %>
7
+ # def title was created automatically because you didn't specify a string field
8
+ # when you ran the refinery_engine generator. Love, Refinery CMS.
9
+ def title
10
+ "Override def title in vendor/engines/<%= plural_name %>/app/models/<%= singular_name %>.rb"
11
+ end
12
+ <% end -%>
13
+ <% attributes.collect{|a| a if a.type.to_s == 'image'}.compact.uniq.each do |a| -%>
14
+
15
+ belongs_to :<%= a.name.gsub("_id", "") -%><%= ", :class_name => 'Image'" unless a.name =~ /^image(_id)?$/ -%>
16
+ <% end -%>
17
+ <% attributes.collect{|a| a if a.type.to_s == 'resource'}.compact.uniq.each do |a| -%>
18
+
19
+ belongs_to :<%= a.name.gsub("_id", "") %><%= ", :class_name => 'Resource'" unless a.name =~ /^resource(_id)?$/ -%>
20
+ <% end %>
21
+ end
@@ -0,0 +1,36 @@
1
+ <%%= form_for [:admin, @<%= singular_name %>] do |f| -%>
2
+ <%%= render :partial => "/shared/admin/error_messages", :locals => {
3
+ :object => @<%= singular_name %>,
4
+ :include_object_name => true
5
+ } %>
6
+ <% attributes.each_with_index do |attribute, index| %>
7
+ <div class='field'>
8
+ <%%= f.label :<%= attribute.name %> -%>
9
+ <% if attribute.type.to_s == 'image' -%>
10
+ <%%= render :partial => "/shared/admin/image_picker", :locals => {
11
+ :f => f,
12
+ :field => :<%= "#{attribute.name}_id".gsub("_id_id", "_id") %>,
13
+ :image => @<%= singular_name %>.<%= attribute.name.gsub("_id", "") %>,
14
+ :toggle_image_display => false
15
+ } %>
16
+ <% elsif attribute.type.to_s == 'resource' %>
17
+ <%%= render :partial => "/shared/admin/resource_picker", :locals => {
18
+ :f => f,
19
+ :field => :<%= "#{attribute.name}_id".gsub("_id_id", "_id") %>,
20
+ :resource => @<%= singular_name %>.<%= attribute.name.gsub("_id", "") %>,
21
+ } %>
22
+ <% elsif attribute.field_type.to_s == "text_area" -%>
23
+ <%%= f.text_area :<%= attribute.name %>, :rows => 20, :class => 'wymeditor widest' -%>
24
+ <% else -%>
25
+ <%%= f.<%= attribute.field_type -%> :<%= attribute.name -%><%= ", :class => 'larger widest'" if (index == 0 && attribute.field_type == :text_field) -%> -%>
26
+ <% end -%>
27
+ </div>
28
+ <% end %>
29
+ <%%= render :partial => "/shared/admin/form_actions",
30
+ :locals => {
31
+ :f => f,
32
+ :continue_editing => false,
33
+ :delete_title => t('delete', :scope => 'admin.<%= plural_name %>.<%= singular_name %>'),
34
+ :delete_confirmation => t('message', :scope => 'shared.admin.delete'<% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>, :title => @<%= singular_name %>.<%= title.name %><% end %>)
35
+ } %>
36
+ <%% end -%>
@@ -0,0 +1,18 @@
1
+ <li class='clearfix record <%%= cycle("on", "on-hover") %>' id="<%%= dom_id(<%= singular_name %>) -%>">
2
+ <span class='title'>
3
+ <%%= <%= singular_name %><% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? -%>.<%= title.name %><% else %>.title<%end %> %>
4
+ <span class="preview">&nbsp;</span>
5
+ </span>
6
+ <span class='actions'>
7
+ <%%= link_to refinery_icon_tag("application_go.png"), <%= singular_name %>_url(<%= singular_name %>),
8
+ :title => t('.view_live_html'),
9
+ :target => "_blank" %>
10
+ <%%= link_to refinery_icon_tag("application_edit.png"), edit_admin_<%= singular_name %>_path(<%= singular_name %>),
11
+ :title => t('.edit') %>
12
+ <%%= link_to refinery_icon_tag("delete.png"), admin_<%= singular_name %>_path(<%= singular_name %>),
13
+ :class => "cancel confirm-delete",
14
+ :title => t('.delete'),
15
+ :confirm => t('message', :scope => 'shared.admin.delete', :title => <%= singular_name %><% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>.<%= title.name %><% else %>.title<% end %>),
16
+ :method => :delete %>
17
+ </span>
18
+ </li>
@@ -0,0 +1,4 @@
1
+ <ul id='sortable_list'>
2
+ <%%= render :partial => '<%= singular_name %>', :collection => @<%= plural_name %> %>
3
+ </ul>
4
+ <%%= render :partial => "/shared/admin/sortable_list", :locals => {:continue_reordering => (defined?(continue_reordering) ? continue_reordering : true)} %>
@@ -0,0 +1 @@
1
+ <%%= render :partial => "form" %>
@@ -0,0 +1,56 @@
1
+ <div id='records'>
2
+ <%% if searching? %>
3
+ <h2><%%= t('results_for', :scope => 'shared.admin.search', :query => params[:search]) %></h2>
4
+ <%% end %>
5
+ <%% if @<%= plural_name %>.any? %>
6
+ <%%= will_paginate @<%= plural_name %> %>
7
+
8
+ <%%= render :partial => "sortable_list" %>
9
+
10
+ <%%= will_paginate @<%= plural_name %> %>
11
+ <%% else %>
12
+ <p>
13
+ <%% unless searching? %>
14
+ <strong>
15
+ <%%= t('.no_items_yet') %>
16
+ </strong>
17
+ <%% else %>
18
+ <%%= t('no_results', :scope => 'shared.admin.search') %>
19
+ <%% end %>
20
+ </p>
21
+ <%% end %>
22
+ </div>
23
+ <div id='actions'>
24
+ <ul>
25
+ <%% if Admin::<%= class_name.pluralize %>Controller.searchable? %>
26
+ <li>
27
+ <%%= render :partial => "/shared/admin/search",
28
+ :locals => {
29
+ :url => admin_<%= plural_name %><%= "_index" if plural_name == singular_name%>_url
30
+ } %>
31
+ </li>
32
+ <%% end %>
33
+ <li>
34
+ <%%= link_to t('.create_new'), new_admin_<%= singular_name %>_url,
35
+ :class => "add_icon" %>
36
+ </li>
37
+ <%% if !searching? and <%= class_name %>.count > 1 and Admin::<%= class_name.pluralize %>Controller.sortable? %>
38
+ <li>
39
+ <%%= link_to t('.reorder', :what => "<%= singular_name.titleize.pluralize %>"),
40
+ admin_<%= plural_name %><%= "_index" if plural_name == singular_name%>_url,
41
+ :id => "reorder_action",
42
+ :class => "reorder_icon" %>
43
+
44
+ <%%= link_to t('.reorder_done', :what => "<%= singular_name.titleize.pluralize %>"),
45
+ admin_<%= plural_name %><%= "_index" if plural_name == singular_name%>_url,
46
+ :id => "reorder_action_done",
47
+ :style => "display: none;",
48
+ :class => "reorder_icon" %>
49
+ </li>
50
+ <%% end %>
51
+ </ul>
52
+ </div>
53
+ <%%= render :partial => "/shared/admin/make_sortable",
54
+ :locals => {
55
+ :tree => false
56
+ } if !searching? and <%= class_name %>.count > 1 %>
@@ -0,0 +1 @@
1
+ <%%= render :partial => "form" %>
@@ -0,0 +1,11 @@
1
+ <%% content_for :body_content_left do %>
2
+ <ul id="<%= plural_name %>">
3
+ <%% @<%= "all_" if plural_name == singular_name%><%= plural_name %>.each do |<%= singular_name %>| %>
4
+ <li>
5
+ <%%= link_to <%= singular_name %><% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>.<%= title.name %><% end %>, <%= singular_name %>_url(<%= singular_name %>) %>
6
+ </li>
7
+ <%% end %>
8
+ </ul>
9
+ <%% end %>
10
+
11
+ <%%= render :partial => "/shared/content_page" %>
@@ -0,0 +1,33 @@
1
+ <%% content_for :body_content_title do %>
2
+ <%%= @<%= singular_name %><% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>.<%= title.name %><% else %>.title<% end %> %>
3
+ <%% end %>
4
+
5
+ <%% content_for :body_content_left do %>
6
+ <% attributes.each do |attribute| %>
7
+ <section>
8
+ <h1><%= attribute.name.titleize %></h1>
9
+ <p><% if attribute.type.to_s == 'image' -%>
10
+ <%%= image_fu @<%= singular_name %>.<%= attribute.name %>, nil %>
11
+ <% elsif attribute.type.to_s == 'resource' -%>
12
+ <%%= link_to <%= "'#{attribute.name}'" %>, @<%= singular_name %>.<%= attribute.name %>.url %>
13
+ <% else -%>
14
+ <%%=raw @<%= singular_name %>.<%= attribute.name %> %>
15
+ <% end -%></p>
16
+ </section>
17
+ <% end %>
18
+ <%% end %>
19
+
20
+ <%% content_for :body_content_right do %>
21
+ <aside>
22
+ <h2><%%= t('.other') %></h2>
23
+ <ul id="<%= plural_name %>">
24
+ <%% @<%= "all_" if plural_name == singular_name%><%= plural_name %>.each do |<%= singular_name %>| %>
25
+ <li>
26
+ <%%= link_to <%= singular_name %><% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>.<%= title.name %><% else %>.title<% end %>, <%= singular_name %>_url(<%= singular_name %>) %>
27
+ </li>
28
+ <%% end %>
29
+ </ul>
30
+ </aside>
31
+ <%% end %>
32
+
33
+ <%%= render :partial => "/shared/content_page" %>
@@ -0,0 +1,24 @@
1
+ en:
2
+ shared:
3
+ admin:
4
+ image_picker:
5
+ image: image
6
+ plugins:
7
+ <%= class_name.pluralize.underscore.downcase %>:
8
+ title: <%= plural_name.titleize %>
9
+ admin:
10
+ <%= plural_name %>:
11
+ index:
12
+ title: <%= plural_name.titleize %>
13
+ create_new: Add New <%= singular_name.titleize %>
14
+ reorder: Reorder <%= singular_name.titleize.pluralize %>
15
+ reorder_done: Done Reordering <%= singular_name.titleize.pluralize %>
16
+ sorry_no_results: Sorry! There are no results found.
17
+ no_items_yet: There are no <%= singular_name.titleize.pluralize %> yet. Click "Add New <%= singular_name.titleize %>" to add your first <%= singular_name.titleize.downcase %>.
18
+ <%= singular_name %>:
19
+ view_live_html: View this <%= singular_name.titleize.downcase %> live <br/><em>(opens in a new window)</em>
20
+ edit: Edit this <%= singular_name.titleize.downcase %>
21
+ delete: Remove this <%= singular_name.titleize.downcase %> forever
22
+ <%= plural_name %>:
23
+ show:
24
+ other: Other <%= singular_name.titleize.pluralize %>
@@ -0,0 +1,24 @@
1
+ lolcat:
2
+ shared:
3
+ admin:
4
+ image_picker:
5
+ image: IMAGE
6
+ plugins:
7
+ <%= class_name.pluralize.underscore.downcase %>:
8
+ title: <%= plural_name.titleize %>
9
+ admin:
10
+ <%= plural_name %>:
11
+ index:
12
+ title: <%= plural_name.titleize %>
13
+ create_new: CREATE NEW <%= singular_name.titleize %>
14
+ reorder: REORDR <%= singular_name.titleize.pluralize %>
15
+ reorder_done: DUN REORDERIN <%= singular_name.titleize.pluralize %>
16
+ sorry_no_results: SRY! THAR R NO RESULTS FINDZ.
17
+ no_items_yet: THAR R NO <%= singular_name.titleize.pluralize %> YET. CLICK "CREATE NEW <%= singular_name.titleize %>" 2 ADD UR FURST <%= singular_name.titleize.downcase %>.
18
+ <%= singular_name %>:
19
+ view_live_html: VIEW DIS <%= singular_name.titleize.downcase %> LIV <BR/><EM>(OPENS IN NEW WINDOW)</EM>
20
+ edit: EDIT DIS <%= singular_name.titleize.downcase %>
21
+ delete: REMOOV DIS <%= singular_name.titleize.downcase %> FOREVR
22
+ <%= plural_name %>:
23
+ show:
24
+ other: OTHR <%= singular_name.titleize.pluralize %>
@@ -0,0 +1,20 @@
1
+ nb:
2
+ plugins:
3
+ <%= class_name.pluralize.underscore.downcase %>:
4
+ title: <%= plural_name.titleize %>
5
+ admin:
6
+ <%= plural_name %>:
7
+ index:
8
+ title: <%= plural_name.titleize %>
9
+ create_new: Lag en ny <%= singular_name.titleize %>
10
+ reorder: Endre rekkefølgen på <%= singular_name.titleize.pluralize %>
11
+ reorder_done: Ferdig å endre rekkefølgen <%= singular_name.titleize.pluralize %>
12
+ sorry_no_results: Beklager! Vi fant ikke noen resultater.
13
+ no_items_yet: Det er ingen <%= singular_name.titleize.pluralize %> enda. Klikk på "Lag en ny <%= singular_name.titleize %>" for å legge til din første <%= singular_name.titleize.downcase %>.
14
+ <%= singular_name %>:
15
+ view_live_html: Vis hvordan denne <%= singular_name.titleize.downcase %> ser ut offentlig <br/><em>(åpner i et nytt vindu)</em>
16
+ edit: Rediger denne <%= singular_name.titleize.downcase %>
17
+ delete: Fjern denne <%= singular_name.titleize.downcase %> permanent
18
+ <%= plural_name %>:
19
+ show:
20
+ other: Andre <%= singular_name.titleize.pluralize %>
@@ -0,0 +1,20 @@
1
+ nl:
2
+ plugins:
3
+ <%= class_name.pluralize.underscore.downcase %>:
4
+ title: <%= plural_name.titleize %>
5
+ admin:
6
+ <%= plural_name %>:
7
+ index:
8
+ title: <%= plural_name.titleize %>
9
+ create_new: Maak een nieuwe <%= singular_name.titleize %>
10
+ reorder: Wijzig de volgorde van de <%= singular_name.titleize.pluralize %>
11
+ reorder_done: Klaar met het wijzingen van de volgorde van de <%= singular_name.titleize.pluralize %>
12
+ sorry_no_results: Helaas! Er zijn geen resultaten gevonden.
13
+ no_items_yet: Er zijn nog geen <%= singular_name.titleize.pluralize %>. Druk op 'Maak een nieuwe <%= singular_name.titleize %>' om de eerste aan te maken.
14
+ <%= singular_name %>:
15
+ view_live_html: Bekijk deze <%= singular_name.titleize.downcase %> op de website <br/><em>(opent een nieuw venster)</em>
16
+ edit: Bewerk deze <%= singular_name.titleize.downcase %>
17
+ delete: Verwijder deze <%= singular_name.titleize.downcase %> voor eeuwig
18
+ <%= plural_name %>:
19
+ show:
20
+ other: Andere <%= singular_name.titleize.pluralize %>
@@ -0,0 +1,11 @@
1
+ Refinery::Application.routes.draw do
2
+ resources :<%= class_name.pluralize.underscore.downcase %>, :only => [:index, :show]
3
+
4
+ scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
5
+ resources :<%= class_name.pluralize.underscore.downcase %>, :except => :show do
6
+ collection do
7
+ post :update_positions
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ class Create<%= class_name.pluralize %> < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :<%= table_name %> do |t|
5
+ <%
6
+ attributes.each do |attribute|
7
+ # turn image or resource into what it was supposed to be which is an integer reference to an image or resource.
8
+ if attribute.type.to_s =~ /^(image|resource)$/
9
+ attribute.type = 'integer'
10
+ attribute.name = "#{attribute.name}_id".gsub("_id_id", "_id")
11
+ end
12
+ -%>
13
+ t.<%= attribute.type %> :<%= attribute.name %>
14
+ <% end -%>
15
+ t.integer :position
16
+
17
+ t.timestamps
18
+ end
19
+
20
+ add_index :<%= table_name %>, :id
21
+
22
+ load(Rails.root.join('db', 'seeds', '<%= class_name.pluralize.underscore.downcase %>.rb'))
23
+ end
24
+
25
+ def self.down
26
+ UserPlugin.destroy_all({:name => "<%= class_name.pluralize.underscore.downcase %>"})
27
+
28
+ Page.delete_all({:link_url => "/<%= plural_name %>"})
29
+
30
+ drop_table :<%= table_name %>
31
+ end
32
+
33
+ end
@@ -0,0 +1,17 @@
1
+ User.find(:all).each do |user|
2
+ if user.plugins.find_by_name('<%= class_name.pluralize.underscore.downcase %>').nil?
3
+ user.plugins.create(:name => '<%= class_name.pluralize.underscore.downcase %>',
4
+ :position => (user.plugins.maximum(:position) || -1) +1)
5
+ end
6
+ end
7
+
8
+ page = Page.create(
9
+ :title => '<%= class_name.pluralize.underscore.titleize %>',
10
+ :link_url => '/<%= plural_name %>',
11
+ :deletable => false,
12
+ :position => ((Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
13
+ :menu_match => '^/<%= plural_name %>(\/|\/.+?|)$'
14
+ )
15
+ Page.default_parts.each do |default_page_part|
16
+ page.parts.create(:title => default_page_part, :body => nil)
17
+ end
@@ -0,0 +1,63 @@
1
+ @<%= plural_name %>
2
+ Feature: <%= plural_name.titleize %>
3
+ In order to have <%= plural_name %> on my website
4
+ As an administrator
5
+ I want to manage <%= plural_name %>
6
+
7
+ Background:
8
+ Given I am a logged in refinery user
9
+ And I have no <%= plural_name %>
10
+ <% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>
11
+ @<%= plural_name %>-list @list
12
+ Scenario: <%= plural_name.titleize %> List
13
+ Given I have <%= plural_name %> titled UniqueTitleOne, UniqueTitleTwo
14
+ When I go to the list of <%= plural_name %>
15
+ Then I should see "UniqueTitleOne"
16
+ And I should see "UniqueTitleTwo"
17
+
18
+ @<%= plural_name %>-valid @valid
19
+ Scenario: Create Valid <%= singular_name.titleize %>
20
+ When I go to the list of <%= plural_name %>
21
+ And I follow "Add New <%= singular_name.titleize %>"
22
+ And I fill in "<%= title.name.titleize %>" with "This is a test of the first string field"
23
+ And I press "Save"
24
+ Then I should see "'This is a test of the first string field' was successfully added."
25
+ And I should have 1 <%= singular_name %>
26
+
27
+ @<%= plural_name %>-invalid @invalid
28
+ Scenario: Create Invalid <%= singular_name.titleize %> (without <%= title.name %>)
29
+ When I go to the list of <%= plural_name %>
30
+ And I follow "Add New <%= singular_name.titleize %>"
31
+ And I press "Save"
32
+ Then I should see "<%= title.name.titleize %> can't be blank"
33
+ And I should have 0 <%= plural_name %>
34
+
35
+ @<%= plural_name %>-edit @edit
36
+ Scenario: Edit Existing <%= singular_name.titleize %>
37
+ Given I have <%= plural_name %> titled "A <%= title.name %>"
38
+ When I go to the list of <%= plural_name %>
39
+ And I follow "Edit this <%= singular_name %>" within ".actions"
40
+ Then I fill in "<%= title.name.titleize %>" with "A different <%= title.name %>"
41
+ And I press "Save"
42
+ Then I should see "'A different <%= title.name %>' was successfully updated."
43
+ And I should be on the list of <%= plural_name %>
44
+ And I should not see "A <%= title.name %>"
45
+
46
+ @<%= plural_name %>-duplicate @duplicate
47
+ Scenario: Create Duplicate <%= singular_name.titleize %>
48
+ Given I only have <%= plural_name %> titled UniqueTitleOne, UniqueTitleTwo
49
+ When I go to the list of <%= plural_name %>
50
+ And I follow "Add New <%= singular_name.titleize %>"
51
+ And I fill in "<%= title.name.titleize %>" with "UniqueTitleTwo"
52
+ And I press "Save"
53
+ Then I should see "There were problems"
54
+ And I should have 2 <%= plural_name %>
55
+
56
+ @<%= plural_name %>-delete @delete
57
+ Scenario: Delete <%= singular_name.titleize %>
58
+ Given I only have <%= plural_name %> titled UniqueTitleOne
59
+ When I go to the list of <%= plural_name %>
60
+ And I follow "Remove this <%= singular_name.titleize.downcase %> forever"
61
+ Then I should see "'UniqueTitleOne' was successfully removed."
62
+ And I should have 0 <%= plural_name %>
63
+ <% end -%>
@@ -0,0 +1,16 @@
1
+ Given /^I have no <%= plural_name %>$/ do
2
+ <%= class_name %>.delete_all
3
+ end
4
+
5
+ <% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? -%>
6
+ Given /^I (only )?have <%= plural_name %> titled "?([^"]*)"?$/ do |only, titles|
7
+ <%= class_name %>.delete_all if only
8
+ titles.split(', ').each do |title|
9
+ <%= class_name %>.create(:<%= title.name %> => title)
10
+ end
11
+ end
12
+ <% end -%>
13
+
14
+ Then /^I should have ([0-9]+) <%= plural_name %>?$/ do |count|
15
+ <%= class_name %>.count.should == count.to_i
16
+ end
@@ -0,0 +1,17 @@
1
+ module NavigationHelpers
2
+ module Refinery
3
+ module <%= class_name.pluralize %><%= 'Engine' if plural_name == singular_name %>
4
+ def path_to(page_name)
5
+ case page_name
6
+ when /the list of <%= plural_name %>/
7
+ admin_<%= plural_name %>_path
8
+
9
+ when /the new <%= singular_name %> form/
10
+ new_admin_<%= singular_name %>_path
11
+ else
12
+ nil
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ class Refinerycms<%= class_name.pluralize %> < Refinery::Generators::EngineInstaller
2
+
3
+ source_root File.expand_path('../../../', __FILE__)
4
+ engine_name "<%= plural_name %>"
5
+
6
+ end
@@ -0,0 +1,20 @@
1
+ require 'refinery'
2
+
3
+ module Refinery
4
+ module <%= class_name.pluralize %><%= 'Engine' if plural_name == singular_name %>
5
+ class Engine < Rails::Engine
6
+ initializer "static assets" do |app|
7
+ app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"
8
+ end
9
+
10
+ config.after_initialize do
11
+ Refinery::Plugin.register do |plugin|
12
+ plugin.name = "<%= class_name.pluralize.underscore.downcase %>"
13
+ plugin.activity = {:class => <%= class_name %><% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? and title.name != 'title' %>,
14
+ :title => '<%= title.name %>'
15
+ <% end %>}
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ namespace :refinery do
2
+
3
+ namespace :<%= plural_name %> do
4
+
5
+ # call this task my running: rake refinery:<%= plural_name %>:my_task
6
+ # desc "Description of my task below"
7
+ # task :my_task => :environment do
8
+ # # add your logic here
9
+ # end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,10 @@
1
+ # <%= plural_name.titleize %> engine for Refinery CMS.
2
+
3
+ ## How to build this engine as a gem
4
+
5
+ cd vendor/engines/<%= plural_name %>
6
+ gem build refinerycms-<%= plural_name %>.gempspec
7
+ gem install refinerycms-<%= plural_name %>.gem
8
+
9
+ # Sign up for a http://rubygems.org/ account and publish the gem
10
+ gem push refinerycms-<%= plural_name %>.gem
@@ -0,0 +1,10 @@
1
+ Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.name = 'refinerycms-<%= plural_name %>'
4
+ s.version = '1.0'
5
+ s.description = 'Ruby on Rails <%= plural_name.titleize %> engine for Refinery CMS'
6
+ s.date = '<%= Time.now.strftime('%Y-%m-%d') %>'
7
+ s.summary = '<%= plural_name.titleize %> engine for Refinery CMS'
8
+ s.require_paths = %w(lib)
9
+ s.files = Dir['lib/**/*', 'config/**/*', 'app/**/*']
10
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe <%= class_name %> do
4
+
5
+ def reset_<%= singular_name %>(options = {})
6
+ @valid_attributes = {
7
+ :id => 1,
8
+ :title => "RSpec is great for testing too"
9
+ }
10
+
11
+ @<%= singular_name %>.destroy! if @<%= singular_name %>
12
+ @<%= singular_name %> = <%= class_name %>.create!(@valid_attributes.update(options))
13
+ end
14
+
15
+ before(:each) do
16
+ reset_<%= singular_name %>
17
+ end
18
+
19
+ context "validations" do
20
+ <% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>
21
+ it "rejects empty <%= title.name %>" do
22
+ <%= class_name %>.new(@valid_attributes.merge(:<%= title.name %> => "")).should_not be_valid
23
+ end
24
+
25
+ it "rejects non unique <%= title.name %>" do
26
+ # as one gets created before each spec by reset_<%= singular_name %>
27
+ <%= class_name %>.new(@valid_attributes).should_not be_valid
28
+ end
29
+ <% end %>
30
+ end
31
+
32
+ end
@@ -0,0 +1,62 @@
1
+ require 'refinery'
2
+
3
+ module Refinery
4
+ module Generators
5
+ # The core engine installer streamlines the installation of custom generated
6
+ # engines. It takes the migrations and seeds in your engine and moves them
7
+ # into the rails app db directory, ready to migrate.
8
+ class EngineInstaller < Rails::Generators::Base
9
+
10
+ include Rails::Generators::Migration
11
+
12
+ attr_accessor :silence_puts
13
+ def silence_puts
14
+ !!@silence_puts
15
+ end
16
+
17
+ class << self
18
+
19
+ def engine_name(name = nil)
20
+ @engine_name = name.to_s unless name.nil?
21
+ @engine_name
22
+ end
23
+
24
+ def source_root(root = nil)
25
+ Pathname.new(super.to_s)
26
+ end
27
+
28
+ # Implement the required interface for Rails::Generators::Migration.
29
+ # taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
30
+ # can be removed once this issue is fixed:
31
+ # # https://rails.lighthouseapp.com/projects/8994/tickets/3820-make-railsgeneratorsmigrationnext_migration_number-method-a-class-method-so-it-possible-to-use-it-in-custom-generators
32
+ def next_migration_number(dirname)
33
+ ::ActiveRecord::Generators::Base.next_migration_number(dirname)
34
+ end
35
+ end
36
+
37
+ def generate
38
+ Pathname.glob(self.class.source_root.join('db', '**', '*.rb')).sort.each do |path|
39
+ case path.to_s
40
+ when %r{.*/migrate/.*}
41
+ # unless the migration has already been generated.
42
+ migration_name = "#{path.split.last.to_s.split(/\d+_/).last}"
43
+ unless Dir[Rails.root.join('db', 'migrate', "*#{migration_name}")].any?
44
+ migration_template path, Rails.root.join('db', 'migrate', path.to_s.split('/migrate/').last.split(/^\d*_/).last)
45
+ else
46
+ puts "You already have a migration called #{migration_name.split('.rb').first}" unless self.silence_puts || self.behavior == :revoke
47
+ end
48
+ when %r{.*/seeds/.*}
49
+ template path, Rails.root.join('db', 'seeds', path.to_s.split('/seeds/').last)
50
+ end
51
+ end
52
+
53
+ unless self.silence_puts || self.behavior == :revoke
54
+ puts "------------------------"
55
+ puts "Now run:"
56
+ puts "rake db:migrate"
57
+ puts "------------------------"
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,43 @@
1
+ require 'refinery'
2
+
3
+ module Refinery
4
+ module Generators
5
+ autoload :EngineInstaller, File.expand_path('../refinery/generators', __FILE__)
6
+
7
+ class Engine < Rails::Engine
8
+ config.after_initialize do
9
+ ::Refinery::Plugin.register do |plugin|
10
+ plugin.name = "refinery_generators"
11
+ plugin.hide_from_menu = true
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ # Below is a hack until this issue:
19
+ # https://rails.lighthouseapp.com/projects/8994/tickets/3820-make-railsgeneratorsmigrationnext_migration_number-method-a-class-method-so-it-possible-to-use-it-in-custom-generators
20
+ # is fixed on the Rails project.
21
+
22
+ require 'rails/generators/named_base'
23
+ require 'rails/generators/migration'
24
+ require 'rails/generators/active_model'
25
+ require 'active_record'
26
+
27
+ module ActiveRecord
28
+ module Generators
29
+ class Base < Rails::Generators::NamedBase #:nodoc:
30
+ include Rails::Generators::Migration
31
+
32
+ # Implement the required interface for Rails::Generators::Migration.
33
+ def self.next_migration_number(dirname) #:nodoc:
34
+ next_migration_number = current_migration_number(dirname) + 1
35
+ if ActiveRecord::Base.timestamped_migrations
36
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
37
+ else
38
+ "%.3d" % next_migration_number
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
data/readme.md ADDED
@@ -0,0 +1,50 @@
1
+ # RefineryCMS Generators
2
+
3
+ ## Dependencies
4
+
5
+ This version requires RefineryCMS >= 0.9.9. Before that, these were built in but we've extracted them to provide greater flexibility for all future versions.
6
+
7
+ ## Engine Generator
8
+
9
+ The Refinery generator is a standard Rails generator that functions just like the scaffold generator. It allows you to quickly add new managed sections to the Refinery backend and get the front end views for free.
10
+
11
+ To see how to use the generator run
12
+
13
+ rails generate refinery_engine
14
+
15
+ Usage instructions should appear.
16
+
17
+ ### Engine Generator Example
18
+
19
+ Let's say you have a client who has a range of products they want to show on their website. You've considered using a few pages to manage the products but you've decided it would be much nicer if there was a separate place that had forms dedicated to managing products.
20
+
21
+ First decide what fields they need to manage. In our case, the client is going to want to edit the title and description of each product. They would also like a little "facts panel" to show on the right of the page.
22
+
23
+ So go to the root of your project and run
24
+
25
+ rails generate refinery_engine
26
+
27
+ This will output the help on how to use the generator. To generate the new section we want to manage products we run:
28
+
29
+ rails generate refinery_engine product title:string description:text image:image brochure:resource
30
+
31
+ The generator will output a list of files it generated. You'll notice there is a new engine that has been added in ``vendor/engines/products``. This is where both the backend and front end files are held for this new products area.
32
+
33
+ Engines are treated like gems. When you generate a new engine it adds the gem dependency for this engine to the end of your ``Gemfile``. Because your ``Gemfile`` has changed you now need to run:
34
+
35
+ bundle install
36
+
37
+ When the products engine was generated a products generator was also created. This installs any migrations and seeds into your Rails app. Here's how to finish off the install
38
+
39
+ rails generate refinerycms_products
40
+ rake db:migrate
41
+
42
+ Start up your app by running ``ruby script/server`` go to [http://localhost:3000](http://localhost:3000) and you'll see instantly a new menu item called "products". Click on that and you'll see there are no products yet.
43
+
44
+ Now go to the backend of your site by visiting [http://localhost:3000/refinery](http://localhost:3000/refinery) and logging in. You'll see a new tab called "Products", click on that and then click "Add a new product", fill the form and add an example product. Now go back to the front end and you'll see your product is showing up in the products part of your site.
45
+
46
+ Now you have a fully managed products section in Refinery, nice.
47
+
48
+ If you want to modify your generated engine you need to understand the basic structure of how they work.
49
+
50
+ See: [The Structure of an Engine](http://github.com/resolve/refinerycms/blob/master/vendor/refinerycms/core/engines.md)
@@ -0,0 +1,85 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{refinerycms-generators}
3
+ s.version = %q{0.9.9}
4
+ s.date = %q{2011-01-26}
5
+ s.summary = %q{Core generators for the Refinery CMS project.}
6
+ s.description = %q{Core generators for Refinery CMS including refinery_engine.}
7
+ s.homepage = %q{http://refinerycms.com}
8
+ s.email = %q{info@refinerycms.com}
9
+ s.authors = ["Resolve Digital"]
10
+ s.require_paths = %w(lib)
11
+
12
+ s.add_dependency 'refinerycms', '>= 0.9.9'
13
+
14
+ s.files = [
15
+ 'features',
16
+ 'features/engine_generator.feature',
17
+ 'features/step_definitions',
18
+ 'features/step_definitions/engine_generator_steps.rb',
19
+ 'features/step_definitions/generator_steps.rb',
20
+ 'features/step_definitions/support',
21
+ 'features/step_definitions/support/paths.rb',
22
+ 'lib',
23
+ 'lib/gemspec.rb',
24
+ 'lib/generators',
25
+ 'lib/generators/refinery_engine',
26
+ 'lib/generators/refinery_engine/refinery_engine_generator.rb',
27
+ 'lib/generators/refinery_engine/templates',
28
+ 'lib/generators/refinery_engine/templates/app',
29
+ 'lib/generators/refinery_engine/templates/app/controllers',
30
+ 'lib/generators/refinery_engine/templates/app/controllers/admin',
31
+ 'lib/generators/refinery_engine/templates/app/controllers/admin/plural_name_controller.rb',
32
+ 'lib/generators/refinery_engine/templates/app/controllers/plural_name_controller.rb',
33
+ 'lib/generators/refinery_engine/templates/app/models',
34
+ 'lib/generators/refinery_engine/templates/app/models/singular_name.rb',
35
+ 'lib/generators/refinery_engine/templates/app/views',
36
+ 'lib/generators/refinery_engine/templates/app/views/admin',
37
+ 'lib/generators/refinery_engine/templates/app/views/admin/plural_name',
38
+ 'lib/generators/refinery_engine/templates/app/views/admin/plural_name/_form.html.erb',
39
+ 'lib/generators/refinery_engine/templates/app/views/admin/plural_name/_singular_name.html.erb',
40
+ 'lib/generators/refinery_engine/templates/app/views/admin/plural_name/_sortable_list.html.erb',
41
+ 'lib/generators/refinery_engine/templates/app/views/admin/plural_name/edit.html.erb',
42
+ 'lib/generators/refinery_engine/templates/app/views/admin/plural_name/index.html.erb',
43
+ 'lib/generators/refinery_engine/templates/app/views/admin/plural_name/new.html.erb',
44
+ 'lib/generators/refinery_engine/templates/app/views/plural_name',
45
+ 'lib/generators/refinery_engine/templates/app/views/plural_name/index.html.erb',
46
+ 'lib/generators/refinery_engine/templates/app/views/plural_name/show.html.erb',
47
+ 'lib/generators/refinery_engine/templates/config',
48
+ 'lib/generators/refinery_engine/templates/config/locales',
49
+ 'lib/generators/refinery_engine/templates/config/locales/en.yml',
50
+ 'lib/generators/refinery_engine/templates/config/locales/lolcat.yml',
51
+ 'lib/generators/refinery_engine/templates/config/locales/nb.yml',
52
+ 'lib/generators/refinery_engine/templates/config/locales/nl.yml',
53
+ 'lib/generators/refinery_engine/templates/config/routes.rb',
54
+ 'lib/generators/refinery_engine/templates/db',
55
+ 'lib/generators/refinery_engine/templates/db/migrate',
56
+ 'lib/generators/refinery_engine/templates/db/migrate/create_plural_name.rb',
57
+ 'lib/generators/refinery_engine/templates/db/seeds',
58
+ 'lib/generators/refinery_engine/templates/db/seeds/plural_name.rb',
59
+ 'lib/generators/refinery_engine/templates/features',
60
+ 'lib/generators/refinery_engine/templates/features/manage_plural_name.feature',
61
+ 'lib/generators/refinery_engine/templates/features/step_definitions',
62
+ 'lib/generators/refinery_engine/templates/features/step_definitions/singular_name_steps.rb',
63
+ 'lib/generators/refinery_engine/templates/features/support',
64
+ 'lib/generators/refinery_engine/templates/features/support/paths.rb',
65
+ 'lib/generators/refinery_engine/templates/lib',
66
+ 'lib/generators/refinery_engine/templates/lib/generators',
67
+ 'lib/generators/refinery_engine/templates/lib/generators/refinerycms_plural_name_generator.rb',
68
+ 'lib/generators/refinery_engine/templates/lib/refinerycms-plural_name.rb',
69
+ 'lib/generators/refinery_engine/templates/lib/tasks',
70
+ 'lib/generators/refinery_engine/templates/lib/tasks/plural_name.rake',
71
+ 'lib/generators/refinery_engine/templates/public',
72
+ 'lib/generators/refinery_engine/templates/readme.md',
73
+ 'lib/generators/refinery_engine/templates/refinerycms-plural_name.gemspec',
74
+ 'lib/generators/refinery_engine/templates/spec',
75
+ 'lib/generators/refinery_engine/templates/spec/models',
76
+ 'lib/generators/refinery_engine/templates/spec/models/singular_name_spec.rb',
77
+ 'lib/generators/refinery_engine/USAGE',
78
+ 'lib/refinery',
79
+ 'lib/refinery/generators.rb',
80
+ 'lib/refinerycms-generators.rb',
81
+ 'readme.md',
82
+ 'refinerycms-generators.gemspec'
83
+ ]
84
+ s.require_path = 'lib'
85
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-generators
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 9
8
+ - 9
9
+ version: 0.9.9
10
+ platform: ruby
11
+ authors:
12
+ - Resolve Digital
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-26 00:00:00 +13:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: refinerycms
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ - 9
31
+ - 9
32
+ version: 0.9.9
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Core generators for Refinery CMS including refinery_engine.
36
+ email: info@refinerycms.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - features/engine_generator.feature
45
+ - features/step_definitions/engine_generator_steps.rb
46
+ - features/step_definitions/generator_steps.rb
47
+ - features/step_definitions/support/paths.rb
48
+ - lib/gemspec.rb
49
+ - lib/generators/refinery_engine/refinery_engine_generator.rb
50
+ - lib/generators/refinery_engine/templates/app/controllers/admin/plural_name_controller.rb
51
+ - lib/generators/refinery_engine/templates/app/controllers/plural_name_controller.rb
52
+ - lib/generators/refinery_engine/templates/app/models/singular_name.rb
53
+ - lib/generators/refinery_engine/templates/app/views/admin/plural_name/_form.html.erb
54
+ - lib/generators/refinery_engine/templates/app/views/admin/plural_name/_singular_name.html.erb
55
+ - lib/generators/refinery_engine/templates/app/views/admin/plural_name/_sortable_list.html.erb
56
+ - lib/generators/refinery_engine/templates/app/views/admin/plural_name/edit.html.erb
57
+ - lib/generators/refinery_engine/templates/app/views/admin/plural_name/index.html.erb
58
+ - lib/generators/refinery_engine/templates/app/views/admin/plural_name/new.html.erb
59
+ - lib/generators/refinery_engine/templates/app/views/plural_name/index.html.erb
60
+ - lib/generators/refinery_engine/templates/app/views/plural_name/show.html.erb
61
+ - lib/generators/refinery_engine/templates/config/locales/en.yml
62
+ - lib/generators/refinery_engine/templates/config/locales/lolcat.yml
63
+ - lib/generators/refinery_engine/templates/config/locales/nb.yml
64
+ - lib/generators/refinery_engine/templates/config/locales/nl.yml
65
+ - lib/generators/refinery_engine/templates/config/routes.rb
66
+ - lib/generators/refinery_engine/templates/db/migrate/create_plural_name.rb
67
+ - lib/generators/refinery_engine/templates/db/seeds/plural_name.rb
68
+ - lib/generators/refinery_engine/templates/features/manage_plural_name.feature
69
+ - lib/generators/refinery_engine/templates/features/step_definitions/singular_name_steps.rb
70
+ - lib/generators/refinery_engine/templates/features/support/paths.rb
71
+ - lib/generators/refinery_engine/templates/lib/generators/refinerycms_plural_name_generator.rb
72
+ - lib/generators/refinery_engine/templates/lib/refinerycms-plural_name.rb
73
+ - lib/generators/refinery_engine/templates/lib/tasks/plural_name.rake
74
+ - lib/generators/refinery_engine/templates/readme.md
75
+ - lib/generators/refinery_engine/templates/refinerycms-plural_name.gemspec
76
+ - lib/generators/refinery_engine/templates/spec/models/singular_name_spec.rb
77
+ - lib/generators/refinery_engine/USAGE
78
+ - lib/refinery/generators.rb
79
+ - lib/refinerycms-generators.rb
80
+ - readme.md
81
+ - refinerycms-generators.gemspec
82
+ has_rdoc: true
83
+ homepage: http://refinerycms.com
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options: []
88
+
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.3.7
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Core generators for the Refinery CMS project.
114
+ test_files: []
115
+