comfy-admin-constructor 0.1.0
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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/comfy-admin-constructor.gemspec +17 -0
- data/lib/comfy-admin-constructor.rb +5 -0
- data/lib/comfy-admin-constructor/version.rb +7 -0
- data/lib/generators/cms_model/USAGE +8 -0
- data/lib/generators/cms_model/cms_model_generator.rb +109 -0
- data/lib/generators/cms_model/templates/actions/create.rb +8 -0
- data/lib/generators/cms_model/templates/actions/destroy.rb +5 -0
- data/lib/generators/cms_model/templates/actions/edit.rb +3 -0
- data/lib/generators/cms_model/templates/actions/index.rb +3 -0
- data/lib/generators/cms_model/templates/actions/new.rb +3 -0
- data/lib/generators/cms_model/templates/actions/update.rb +5 -0
- data/lib/generators/cms_model/templates/controller.rb +12 -0
- data/lib/generators/cms_model/templates/migration.rb +16 -0
- data/lib/generators/cms_model/templates/model.rb +26 -0
- data/lib/generators/cms_model/templates/protected/build.rb +3 -0
- data/lib/generators/cms_model/templates/protected/load.rb +6 -0
- data/lib/generators/cms_model/templates/views/_form.html.haml +6 -0
- data/lib/generators/cms_model/templates/views/edit.html.haml +4 -0
- data/lib/generators/cms_model/templates/views/index.html.haml +19 -0
- data/lib/generators/cms_model/templates/views/new.html.haml +4 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Brian Gilham
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Comfy::Admin::Constructor
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'comfy-admin-constructor'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install comfy-admin-constructor
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/comfy-admin-constructor/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Brian Gilham"]
|
6
|
+
gem.email = ["me@briangilham.com"]
|
7
|
+
gem.description = "Generate a new CMS admin section by providing a model name, along with attributes."
|
8
|
+
gem.summary = "Comfy Admin Constructor - Create CMS admin sections in one line"
|
9
|
+
gem.homepage = "http://www.theworkinggroup.ca"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "comfy-admin-constructor"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Comfy::Admin::Constructor::VERSION
|
17
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
require 'rails/generators/generated_attribute'
|
3
|
+
|
4
|
+
class CmsModelGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
no_tasks { attr_accessor :scaffold_name, :model_attributes, :controller_actions }
|
7
|
+
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
|
10
|
+
argument :model_name, :type => :string, :required => true
|
11
|
+
argument :args_for_c_m, :type => :array, :required => true
|
12
|
+
|
13
|
+
def initialize(*args, &block)
|
14
|
+
super
|
15
|
+
|
16
|
+
@model_attributes = []
|
17
|
+
|
18
|
+
args_for_c_m.each do |arg|
|
19
|
+
if arg.include?(':')
|
20
|
+
@model_attributes << Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
@model_attributes.uniq!
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_model
|
28
|
+
template 'model.rb', "app/models/#{model_path}.rb"
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_migration
|
32
|
+
migration_template 'migration.rb', "db/migrate/create_#{model_path.pluralize.gsub('/', '_')}.rb"
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_controller
|
36
|
+
template 'controller.rb', "app/controllers/admin/#{plural_name}_controller.rb"
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_form
|
40
|
+
template "views/_form.html.haml", "app/views/admin/#{plural_name}/_form.html.haml"
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_views
|
44
|
+
%w[edit index new].each do |action|
|
45
|
+
template "views/#{action}.html.haml", "app/views/admin/#{plural_name}/#{action}.html.haml"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_route
|
50
|
+
namespaces = ["admin", class_name.underscore.downcase.pluralize]
|
51
|
+
resource = namespaces.pop
|
52
|
+
route namespaces.reverse.inject("resources :#{resource}, :except => [:show]") { |acc, namespace|
|
53
|
+
"namespace(:#{namespace}){ #{acc} }"
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def model_path
|
60
|
+
model_name.underscore
|
61
|
+
end
|
62
|
+
|
63
|
+
def plural_name
|
64
|
+
model_name.underscore.pluralize
|
65
|
+
end
|
66
|
+
|
67
|
+
def class_name
|
68
|
+
model_name.camelize
|
69
|
+
end
|
70
|
+
|
71
|
+
def table_name
|
72
|
+
plural_name.gsub('/', '_')
|
73
|
+
end
|
74
|
+
|
75
|
+
def attributes_accessible
|
76
|
+
model_attributes.inspect
|
77
|
+
end
|
78
|
+
|
79
|
+
# FIXME: Should be proxied to ActiveRecord::Generators::Base
|
80
|
+
# Implement the required interface for Rails::Generators::Migration.
|
81
|
+
def self.next_migration_number(dirname) #:nodoc:
|
82
|
+
if ActiveRecord::Base.timestamped_migrations
|
83
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
84
|
+
else
|
85
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def plural_class_name
|
90
|
+
plural_name.camelize
|
91
|
+
end
|
92
|
+
|
93
|
+
def controller_methods(dir_name)
|
94
|
+
%w[index new create edit update destroy].map do |action|
|
95
|
+
read_template("#{dir_name}/#{action}.rb")
|
96
|
+
end.join("\n\n").strip
|
97
|
+
end
|
98
|
+
|
99
|
+
def protected_controller_methods(dir_name)
|
100
|
+
%w[load build].map do |action|
|
101
|
+
read_template("#{dir_name}/#{action}.rb")
|
102
|
+
end.join("\n\n").strip
|
103
|
+
end
|
104
|
+
|
105
|
+
def read_template(relative_path)
|
106
|
+
ERB.new(File.read(find_in_source_paths(relative_path)), nil, '-').result(binding)
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
def create
|
2
|
+
@<%= class_name.underscore.downcase %>.save!
|
3
|
+
flash[:notice] = "<%= class_name.underscore.humanize.downcase.titleize %> created"
|
4
|
+
redirect_to(:action => :index)
|
5
|
+
rescue ActiveRecord::RecordInvalid
|
6
|
+
flash.now[:error] = 'Failed to create <%= class_name.underscore.humanize.downcase.titleize %>'
|
7
|
+
render :action => :new
|
8
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Admin::<%= plural_class_name %>Controller < CmsAdmin::BaseController
|
2
|
+
|
3
|
+
before_filter :load_<%= class_name.underscore.downcase %>, :except => [ :index, :new, :create ]
|
4
|
+
before_filter :build_<%= class_name.underscore.downcase %>, :only => [ :new, :create ]
|
5
|
+
|
6
|
+
<%= controller_methods :actions %>
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
<%= protected_controller_methods :protected %>
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Create<%= class_name.pluralize.delete('::') %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= table_name || plural_name.split('/').last %> 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 :<%= table_name || plural_name.split('/').last %>
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class <%= class_name %> < ActiveRecord::Base
|
2
|
+
|
3
|
+
<%= "set_table_name :#{table_name}\n" if table_name -%>
|
4
|
+
|
5
|
+
attr_accessible <%= model_attributes.map { |a| ":#{a.name}" }.join(", ") %>
|
6
|
+
|
7
|
+
# == Constants ============================================================
|
8
|
+
|
9
|
+
# == Extensions ===========================================================
|
10
|
+
|
11
|
+
# == Relationships ========================================================
|
12
|
+
|
13
|
+
# == Validations ==========================================================
|
14
|
+
|
15
|
+
validates <%= model_attributes.map { |a| ":#{a.name}" }.join(", ") %>,
|
16
|
+
:presence => true
|
17
|
+
|
18
|
+
# == Scopes ===============================================================
|
19
|
+
|
20
|
+
# == Callbacks ============================================================
|
21
|
+
|
22
|
+
# == Class Methods ========================================================
|
23
|
+
|
24
|
+
# == Instance Methods =====================================================
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
def load_<%= class_name.underscore.downcase %>
|
2
|
+
@<%= class_name.underscore.downcase %> = <%= class_name %>.find(params[:id])
|
3
|
+
rescue ActiveRecord::RecordNotFound
|
4
|
+
flash[:error] = '<%= class_name.underscore.humanize.downcase.titleize %> not found'
|
5
|
+
redirect_to :action => :index
|
6
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<%- for attribute in model_attributes -%>
|
2
|
+
= form.<%= attribute.field_type %> :<%= attribute.name %>
|
3
|
+
<%- end -%>
|
4
|
+
|
5
|
+
= form.simple_field(nil, nil, :class => 'submit_element') do
|
6
|
+
= form.submit @<%= class_name.underscore.downcase %>.new_record? ? 'create' : 'update', :disable_builder => true
|
@@ -0,0 +1,19 @@
|
|
1
|
+
= link_to "New <%= class_name.underscore.humanize.downcase.titleize %>", new_admin_<%= class_name.underscore.downcase %>_path, :class => 'big button'
|
2
|
+
|
3
|
+
%h1 <%= class_name.underscore.humanize.downcase.titleize.pluralize %>
|
4
|
+
|
5
|
+
%ul.list
|
6
|
+
- if @<%= class_name.underscore.downcase.pluralize %>.empty?
|
7
|
+
%li
|
8
|
+
.item
|
9
|
+
.sublabel
|
10
|
+
No <%= class_name.underscore.humanize.downcase.titleize.pluralize %> Found
|
11
|
+
- else
|
12
|
+
- @<%= class_name.underscore.downcase.pluralize %>.each do |<%= class_name.underscore.downcase %>|
|
13
|
+
%li
|
14
|
+
.item
|
15
|
+
.icon
|
16
|
+
.action_links
|
17
|
+
= link_to "Edit", edit_admin_<%= class_name.underscore.downcase %>_path(<%= class_name.underscore.downcase %>)
|
18
|
+
= link_to "Delete", admin_<%= class_name.underscore.downcase %>_path(<%= class_name.underscore.downcase %>), :method => :delete, :data => { :confirm => 'Are you sure?' }
|
19
|
+
.label= <%= class_name.underscore.downcase %>.<%= model_attributes.first.name %>
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: comfy-admin-constructor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Gilham
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-21 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Generate a new CMS admin section by providing a model name, along with
|
15
|
+
attributes.
|
16
|
+
email:
|
17
|
+
- me@briangilham.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- comfy-admin-constructor.gemspec
|
28
|
+
- lib/comfy-admin-constructor.rb
|
29
|
+
- lib/comfy-admin-constructor/version.rb
|
30
|
+
- lib/generators/cms_model/USAGE
|
31
|
+
- lib/generators/cms_model/cms_model_generator.rb
|
32
|
+
- lib/generators/cms_model/templates/actions/create.rb
|
33
|
+
- lib/generators/cms_model/templates/actions/destroy.rb
|
34
|
+
- lib/generators/cms_model/templates/actions/edit.rb
|
35
|
+
- lib/generators/cms_model/templates/actions/index.rb
|
36
|
+
- lib/generators/cms_model/templates/actions/new.rb
|
37
|
+
- lib/generators/cms_model/templates/actions/update.rb
|
38
|
+
- lib/generators/cms_model/templates/controller.rb
|
39
|
+
- lib/generators/cms_model/templates/migration.rb
|
40
|
+
- lib/generators/cms_model/templates/model.rb
|
41
|
+
- lib/generators/cms_model/templates/protected/build.rb
|
42
|
+
- lib/generators/cms_model/templates/protected/load.rb
|
43
|
+
- lib/generators/cms_model/templates/views/_form.html.haml
|
44
|
+
- lib/generators/cms_model/templates/views/edit.html.haml
|
45
|
+
- lib/generators/cms_model/templates/views/index.html.haml
|
46
|
+
- lib/generators/cms_model/templates/views/new.html.haml
|
47
|
+
homepage: http://www.theworkinggroup.ca
|
48
|
+
licenses: []
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.17
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Comfy Admin Constructor - Create CMS admin sections in one line
|
71
|
+
test_files: []
|