spree_scaffold 0.60.0.RC1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ tmp
8
+ nbproject
9
+ *.swp
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ SpreeScaffold
2
+ =============
3
+
4
+ A basic admin scaffold generator for Spree.
5
+
6
+ Creates a CRUD interface for whatever you want using the Spree admin styling.
7
+
8
+ It also creates an admin menu item using Deface::Override in an initializer. Don't forget to restart the app for the button to show up in the admin menu bar.
9
+
10
+ Example
11
+ =======
12
+
13
+ To install
14
+
15
+ gem "spree_scaffold", :git => 'git://github.com/sebastyuiop/spree_scaffold.git'
16
+
17
+ To generate a scaffold:
18
+
19
+ rails g spree:scaffold Cat name:string colour:string
20
+
21
+ Which produces:
22
+
23
+ create app/models/cat.rb
24
+ create app/controllers/admin/cats_controller.rb
25
+ create app/views/admin/cats/index.html.erb
26
+ create app/views/admin/cats/new.html.erb
27
+ create app/views/admin/cats/edit.html.erb
28
+ create app/views/admin/cats/_form.html.erb
29
+ create db/migrate/20110620133021_create_cats.rb
30
+ create config/locales/en_cats.yml
31
+ create config/initializers/spree_scaffold_cats_hooks.rb
32
+
33
+ rake db:migrate
34
+
35
+ You'll need to add a route under the admin namespace for the above (e.g resources :cats).
36
+
37
+ Copyright (c) 2011 sebastyuiop, released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/Versionfile ADDED
@@ -0,0 +1,9 @@
1
+ # This file is used to designate compatibilty with different versions of Spree
2
+ # Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
3
+
4
+ # Examples
5
+ #
6
+ # "0.50.x" => { :branch => "master" }
7
+ # "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" }
8
+
9
+
@@ -0,0 +1,18 @@
1
+ Description:
2
+ A basic admin scaffold generator for Spree
3
+ Creates a CRUD interface for whatever you want using the Spree admin styling
4
+ It also creates an initializer that insert an admin menu item for the model you created
5
+
6
+ Example:
7
+ rails generate spree:scaffold ModelName attribute_1:type_1 attribute_2:type_2
8
+
9
+ This will create:
10
+ app/models/model_name.rb
11
+ app/controllers/admin/model_names_controller.rb
12
+ app/views/admin/model_names/index.html.erb
13
+ app/views/admin/model_names/new.html.erb
14
+ app/views/admin/model_names/edit.html.erb
15
+ app/views/admin/model_names/_form.html.erb
16
+ db/migrate/TIMESTAMP_create_model_names.rb
17
+ config/locales/en_model_names.yml
18
+ config/initializers/spree_scaffold_model_names_hooks.rb
@@ -0,0 +1,79 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/generated_attribute'
3
+
4
+ module Spree
5
+ module Generators
6
+ class ScaffoldGenerator < Rails::Generators::Base
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ attr_accessor :scaffold_name, :model_attributes, :controller_actions
10
+
11
+ argument :scaffold_name, :type => :string, :required => true, :banner => 'ModelName'
12
+ argument :model_attribute_args, :type => :array, :default => [], :banner => 'model:attributes'
13
+
14
+ def initialize(*args, &block)
15
+ super
16
+ print_usage unless scaffold_name.underscore =~ /^[a-z][a-z0-9_\/]+$/
17
+
18
+ @model_attributes = []
19
+ model_attribute_args.each do |arg|
20
+ if arg.include?(':')
21
+ @model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
22
+ end
23
+ end
24
+ end
25
+
26
+ def create_model
27
+ template 'model.rb', "app/models/#{model_path}.rb"
28
+ end
29
+
30
+ def create_controller
31
+ template 'controller.rb', "app/controllers/admin/#{model_path.pluralize}_controller.rb"
32
+ end
33
+
34
+ def create_views
35
+ ['index','new','edit'].each do |view|
36
+ template "views/#{view}.html.erb", "app/views/admin/#{model_path.pluralize}/#{view}.html.erb"
37
+ end
38
+ template "views/_form.html.erb", "app/views/admin/#{model_path.pluralize}/_form.html.erb"
39
+ end
40
+
41
+ def create_migration
42
+ stamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
43
+ template 'migration.rb', "db/migrate/#{stamp}_create_#{model_path.pluralize}.rb"
44
+ end
45
+
46
+ def create_locale
47
+ template 'en.yml', "config/locales/en_#{model_path.pluralize}.yml"
48
+ end
49
+
50
+ # Added back since using deface
51
+ def create_hooks
52
+ template 'hooks.rb', "config/initializers/spree_scaffold_#{model_path.pluralize}_hooks.rb"
53
+ end
54
+
55
+ private
56
+
57
+ def model_path
58
+ scaffold_name.underscore.downcase
59
+ end
60
+
61
+ def class_name
62
+ scaffold_name.camelize
63
+ end
64
+
65
+ def table_name
66
+ scaffold_name.downcase.underscore.pluralize
67
+ end
68
+
69
+ def display_name
70
+ scaffold_name.underscore.titleize
71
+ end
72
+
73
+ def display_name_plural
74
+ scaffold_name.underscore.titleize.pluralize
75
+ end
76
+
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,42 @@
1
+ class Admin::<%= class_name.pluralize %>Controller < Admin::ResourceController
2
+
3
+ def index
4
+ @<%= model_path.pluralize %> = <%= class_name %>.page(params[:page] || 1).per(50)
5
+ end
6
+
7
+ def new
8
+ @<%= model_path %> = <%= class_name %>.new
9
+ end
10
+
11
+ def create
12
+ @<%= model_path %> = <%= class_name %>.new(params[:<%= model_path %>])
13
+ if @<%= model_path %>.save
14
+ flash[:notice] = "Successfully created <%= display_name %>."
15
+ redirect_to admin_<%= model_path.pluralize %>_url
16
+ else
17
+ render :action => 'new'
18
+ end
19
+ end
20
+
21
+ def edit
22
+ @<%= model_path %> = <%= class_name %>.find(params[:id])
23
+ end
24
+
25
+ def update
26
+ @page = <%= class_name %>.find(params[:id])
27
+ if @<%= model_path %>.update_attributes(params[:<%= model_path %>])
28
+ flash[:notice] = "Successfully updated <%= display_name %>."
29
+ redirect_to admin_<%= model_path.pluralize %>_url
30
+ else
31
+ render :action => 'edit'
32
+ end
33
+ end
34
+
35
+ def destroy
36
+ @<%= model_path %> = <%= class_name %>.find(params[:id])
37
+ @<%= model_path %>.destroy
38
+ flash[:notice] = "Successfully destroyed <%= display_name %>."
39
+ redirect_to admin_<%= model_path.pluralize %>_url
40
+ end
41
+
42
+ end
@@ -0,0 +1,4 @@
1
+ en:
2
+ new_<%= model_path %>: "New <%= display_name %>"
3
+ listing_<%= model_path.pluralize %>: "Listing <%= display_name_plural %>"
4
+ editing_<%= model_path %>: "Editing <%= display_name %>"
@@ -0,0 +1,5 @@
1
+ Deface::Override.new(:virtual_path => 'layouts/admin',
2
+ :name => 'add_<%= class_name %>_model_to_tabs',
3
+ :insert_bottom => "[data-hook='admin_tabs']",
4
+ :text => '<%%= tab(:<%= model_path.pluralize %>) %>',
5
+ :disabled => false)
@@ -0,0 +1,16 @@
1
+ class Create<%= class_name.pluralize %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= model_path.pluralize %> do |t|
4
+ <%- for attribute in model_attributes -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <%- end -%>
7
+ <%- unless options[:skip_timestamps] -%>
8
+ t.timestamps
9
+ <%- end -%>
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :<%= model_path.pluralize %>
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,6 @@
1
+ <%- for attribute in model_attributes -%>
2
+ <p>
3
+ <%%= f.label :<%= attribute.name %> %><br />
4
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
5
+ </p>
6
+ <%- end -%>
@@ -0,0 +1,14 @@
1
+ <%%= hook :admin_<%= model_path %>_edit_form_header do %>
2
+ <%%= render 'shared/error_messages', :target => @<%= model_path %> %>
3
+ <h1><%%= t("editing_<%= model_path %>") %></h1>
4
+ <%% end %>
5
+
6
+ <%%= hook :admin_<%= model_path %>_edit_form do %>
7
+ <%%= form_for(:<%= model_path %>, :url => object_url, :html => { :method => :put }) do |f| %>
8
+ <%%= render :partial => "form", :locals => { :f => f } %>
9
+
10
+ <%%= hook :admin_<%= model_path %>_edit_form_buttons do %>
11
+ <%%= render :partial => "admin/shared/edit_resource_links" %>
12
+ <%% end %>
13
+ <%% end %>
14
+ <%% end %>
@@ -0,0 +1,36 @@
1
+ <div class='toolbar'>
2
+ <ul class='actions'>
3
+ <li>
4
+ <p><%%= button_link_to t("new_<%= model_path %>"), new_object_url, :icon => 'add' %></p>
5
+ </li>
6
+ </ul>
7
+ <br class='clear' />
8
+ </div>
9
+
10
+ <h1><%%= t("listing_<%= model_path.pluralize %>") %></h1>
11
+
12
+ <table class="index">
13
+ <thead>
14
+ <tr>
15
+ <% for attribute in model_attributes -%>
16
+ <th><%= attribute.name %></th>
17
+ <% end %>
18
+ <th>&nbsp;</th>
19
+ </tr>
20
+ </thead>
21
+ <tbody>
22
+ <%% @<%= model_path.pluralize %>.each do |<%= model_path %>|%>
23
+ <tr id="<%%= dom_id <%= model_path %> %>">
24
+ <% for attribute in model_attributes -%>
25
+ <td width="350px"><%%= link_to <%= model_path %>.<%= attribute.name %>, edit_object_url(<%= model_path %>) %></td>
26
+ <% end %>
27
+ <td>
28
+ <%%= link_to_edit <%= model_path %> %> &nbsp;
29
+ <%%= link_to_delete <%= model_path %> %>
30
+ </td>
31
+ </tr>
32
+ <%% end %>
33
+ </tbody>
34
+ </table>
35
+
36
+ <%%= paginate @<%= model_path.pluralize %> %>
@@ -0,0 +1,14 @@
1
+ <%%= hook :admin_<%= model_path %>_new_form_header do %>
2
+ <%%= render 'shared/error_messages', :target => @<%= model_path %> %>
3
+ <h1><%%= t("new_<%= model_path %>") %></h1>
4
+ <%% end %>
5
+
6
+ <%%= hook :admin_<%= model_path %>_new_form do %>
7
+ <%%= form_for(:<%= model_path %>, :url => collection_url) do |f| %>
8
+ <%%= render :partial => "form", :locals => { :f => f } %>
9
+
10
+ <%%= hook :admin_<%= model_path %>_new_form_buttons do %>
11
+ <%%= render :partial => "admin/shared/new_resource_links" %>
12
+ <%% end %>
13
+ <%% end %>
14
+ <%% end %>
@@ -0,0 +1,18 @@
1
+ require 'deface'
2
+ require 'spree_core'
3
+ require 'spree_scaffold_hooks'
4
+
5
+ module SpreeScaffold
6
+ class Engine < Rails::Engine
7
+
8
+ config.autoload_paths += %W(#{config.root}/lib)
9
+
10
+ def self.activate
11
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
12
+ Rails.env.production? ? require(c) : load(c)
13
+ end
14
+ end
15
+
16
+ config.to_prepare &method(:activate).to_proc
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ class SpreeScaffoldHooks < Spree::ThemeSupport::HookListener
2
+ # custom hooks go here
3
+ end
@@ -0,0 +1,29 @@
1
+ namespace :spree do
2
+
3
+ namespace :scaffold do
4
+
5
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
6
+ task :install do
7
+ Rake::Task['spree:scaffold:install:migrations'].invoke
8
+ Rake::Task['spree:scaffold:install:assets'].invoke
9
+ end
10
+
11
+ namespace :install do
12
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
13
+ task :migrations do
14
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
15
+ destination = File.join(Rails.root, 'db')
16
+ Spree::FileUtilz.mirror_files(source, destination)
17
+ end
18
+
19
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
20
+ task :assets do
21
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
22
+ destination = File.join(Rails.root, 'public')
23
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
24
+ Spree::FileUtilz.mirror_files(source, destination)
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
@@ -0,0 +1,30 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+ require File.expand_path("../test_app/config/environment", __FILE__)
5
+ require 'rspec/rails'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ # == Mock Framework
13
+ #
14
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
15
+ #
16
+ # config.mock_with :mocha
17
+ # config.mock_with :flexmock
18
+ # config.mock_with :rr
19
+ config.mock_with :rspec
20
+
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
22
+
23
+ #config.include Devise::TestHelpers, :type => :controller
24
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
25
+ # examples within a transaction, comment the following line or assign false
26
+ # instead of true.
27
+ config.use_transactional_fixtures = true
28
+ end
29
+
30
+ @configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.name = 'spree_scaffold'
4
+ s.version = '0.60.0.RC1'
5
+ s.summary = 'Add gem summary here'
6
+ s.description = 'Add (optional) gem description here'
7
+ s.required_ruby_version = '>= 1.8.7'
8
+
9
+ s.author = 'Seb Weston'
10
+ s.email = 'seb@example.com'
11
+ s.homepage = 'http://www.github.com/sebastyuiop'
12
+ # s.rubyforge_project = 'actionmailer'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.require_path = 'lib'
17
+ s.requirements << 'none'
18
+
19
+ s.add_dependency('spree_core', '>= 0.60.0.RC1')
20
+ s.add_dependency('deface', '> 0')
21
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_scaffold
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.60.0.RC1
5
+ prerelease: 7
6
+ platform: ruby
7
+ authors:
8
+ - Seb Weston
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: spree_core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.60.0.RC1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.60.0.RC1
30
+ - !ruby/object:Gem::Dependency
31
+ name: deface
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>'
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>'
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Add (optional) gem description here
47
+ email: seb@example.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - .gitignore
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - Versionfile
57
+ - lib/generators/spree/scaffold/USAGE
58
+ - lib/generators/spree/scaffold/scaffold_generator.rb
59
+ - lib/generators/spree/scaffold/templates/controller.rb
60
+ - lib/generators/spree/scaffold/templates/en.yml
61
+ - lib/generators/spree/scaffold/templates/hooks.rb
62
+ - lib/generators/spree/scaffold/templates/migration.rb
63
+ - lib/generators/spree/scaffold/templates/model.rb
64
+ - lib/generators/spree/scaffold/templates/views/_form.html.erb
65
+ - lib/generators/spree/scaffold/templates/views/edit.html.erb
66
+ - lib/generators/spree/scaffold/templates/views/index.html.erb
67
+ - lib/generators/spree/scaffold/templates/views/new.html.erb
68
+ - lib/spree_scaffold.rb
69
+ - lib/spree_scaffold_hooks.rb
70
+ - lib/tasks/install.rake
71
+ - lib/tasks/spree_scaffold.rake
72
+ - spec/spec_helper.rb
73
+ - spree_scaffold.gemspec
74
+ homepage: http://www.github.com/sebastyuiop
75
+ licenses: []
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 1.8.7
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>'
90
+ - !ruby/object:Gem::Version
91
+ version: 1.3.1
92
+ requirements:
93
+ - none
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.23
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Add gem summary here
99
+ test_files:
100
+ - spec/spec_helper.rb