ouvrages_scaffold 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/lib/generators/ouvrages/controller/USAGE +20 -0
- data/lib/generators/ouvrages/controller/controller_generator.rb +22 -0
- data/lib/generators/ouvrages/controller/templates/controller.rb +79 -0
- data/lib/generators/ouvrages/locales/USAGE +6 -0
- data/lib/generators/ouvrages/locales/locales_generator.rb +144 -0
- data/lib/generators/ouvrages/locales/templates/en.yml +43 -0
- data/lib/generators/ouvrages/locales/templates/fr.yml +48 -0
- data/lib/generators/ouvrages/routes/USAGE +5 -0
- data/lib/generators/ouvrages/routes/routes_generator.rb +11 -0
- data/lib/generators/ouvrages/scaffold/scaffold_generator.rb +23 -0
- data/lib/generators/ouvrages/views/templates/_form.html.haml +8 -0
- data/lib/generators/ouvrages/views/templates/edit.html.haml +6 -0
- data/lib/generators/ouvrages/views/templates/index.html.haml +26 -0
- data/lib/generators/ouvrages/views/templates/new.html.haml +6 -0
- data/lib/generators/ouvrages/views/templates/show.html.haml +15 -0
- data/lib/generators/ouvrages/views/templates/simple_form/_form.html.haml +11 -0
- data/lib/generators/ouvrages/views/views_generator.rb +99 -0
- data/lib/ouvrages_scaffold/version.rb +3 -0
- data/lib/ouvrages_scaffold.rb +4 -0
- data/ouvrages_scaffold.gemspec +24 -0
- metadata +102 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Michael Witrant
|
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,48 @@
|
|
1
|
+
# Ouvrages Scaffold
|
2
|
+
|
3
|
+
Rails generators that produce HAML views to be used with Bootstrap and Cancan.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ouvrages_scaffold'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
gem install ouvrages_scaffold
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
First generate your model with Rails and migrate:
|
22
|
+
|
23
|
+
rails g model Post title:string body:text
|
24
|
+
rake db:migrate
|
25
|
+
|
26
|
+
Then generate the scaffold with:
|
27
|
+
|
28
|
+
rails g ouvrages:scaffold Post
|
29
|
+
|
30
|
+
You can also run the generators individually:
|
31
|
+
|
32
|
+
rails g ouvrages:controller Post
|
33
|
+
rails g ouvrages:routes Post
|
34
|
+
rails g ouvrages:views Post
|
35
|
+
|
36
|
+
If you want to change the model and regenerate the scaffold, you must update the database and call the generator again (you only need to update the views):
|
37
|
+
|
38
|
+
rails g migration AddActiveToPost active:boolean
|
39
|
+
rake db:migrate
|
40
|
+
rails g ouvrages:views Post
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Description:
|
2
|
+
Stubs out a scaffolded controller and its views. Pass the model name,
|
3
|
+
either CamelCased or under_scored, and a list of views as arguments.
|
4
|
+
The controller name is retrieved as a pluralized version of the model
|
5
|
+
name.
|
6
|
+
|
7
|
+
To create a controller within a module, specify the model name as a
|
8
|
+
path like 'parent_module/controller_name'.
|
9
|
+
|
10
|
+
This generates a controller class in app/controllers and invokes helper,
|
11
|
+
template engine and test framework generators.
|
12
|
+
|
13
|
+
Example:
|
14
|
+
`rails generate scaffold_controller CreditCard`
|
15
|
+
|
16
|
+
Credit card controller with URLs like /credit_card/debit.
|
17
|
+
Controller: app/controllers/credit_cards_controller.rb
|
18
|
+
Functional Test: test/functional/credit_cards_controller_test.rb
|
19
|
+
Views: app/views/credit_cards/index.html.erb [...]
|
20
|
+
Helper: app/helpers/credit_cards_helper.rb
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/generators/resource_helpers'
|
2
|
+
|
3
|
+
module Ouvrages
|
4
|
+
module Generators
|
5
|
+
class ControllerGenerator < Rails::Generators::NamedBase
|
6
|
+
include Rails::Generators::ResourceHelpers
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
check_class_collision :suffix => "Controller"
|
10
|
+
|
11
|
+
class_option :orm, :banner => "NAME", :type => :string, :required => true,
|
12
|
+
:desc => "ORM to generate the controller for"
|
13
|
+
|
14
|
+
class_option :http, :type => :boolean, :default => false,
|
15
|
+
:desc => "Generate controller with HTTP actions only"
|
16
|
+
|
17
|
+
def create_controller_files
|
18
|
+
template "controller.rb", File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
3
|
+
load_and_authorize_resource
|
4
|
+
|
5
|
+
before_filter do
|
6
|
+
add_crumb t("navigation.<%= plural_table_name %>"), <%= plural_table_name %>_path
|
7
|
+
end
|
8
|
+
|
9
|
+
# GET <%= route_url %>
|
10
|
+
# GET <%= route_url %>.json
|
11
|
+
def index
|
12
|
+
respond_to do |format|
|
13
|
+
format.html # index.html.erb
|
14
|
+
format.json { render json: <%= "@#{plural_table_name}" %> }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# GET <%= route_url %>/1
|
19
|
+
# GET <%= route_url %>/1.json
|
20
|
+
def show
|
21
|
+
respond_to do |format|
|
22
|
+
format.html # show.html.erb
|
23
|
+
format.json { render json: <%= "@#{singular_table_name}" %> }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# GET <%= route_url %>/new
|
28
|
+
# GET <%= route_url %>/new.json
|
29
|
+
def new
|
30
|
+
respond_to do |format|
|
31
|
+
format.html # new.html.erb
|
32
|
+
format.json { render json: <%= "@#{singular_table_name}" %> }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# GET <%= route_url %>/1/edit
|
37
|
+
def edit
|
38
|
+
end
|
39
|
+
|
40
|
+
# POST <%= route_url %>
|
41
|
+
# POST <%= route_url %>.json
|
42
|
+
def create
|
43
|
+
respond_to do |format|
|
44
|
+
if @<%= orm_instance.save %>
|
45
|
+
format.html { redirect_to @<%= singular_table_name %>, flash: {success: t("<%= plural_table_name %>.created")} }
|
46
|
+
format.json { render json: <%= "@#{singular_table_name}" %>, status: :created, location: <%= "@#{singular_table_name}" %> }
|
47
|
+
else
|
48
|
+
format.html { render action: "new" }
|
49
|
+
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# PATCH/PUT <%= route_url %>/1
|
55
|
+
# PATCH/PUT <%= route_url %>/1.json
|
56
|
+
def update
|
57
|
+
respond_to do |format|
|
58
|
+
if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
|
59
|
+
format.html { redirect_to @<%= singular_table_name %>, flash: {success: t("<%= plural_table_name %>.updated")} }
|
60
|
+
format.json { head :no_content }
|
61
|
+
else
|
62
|
+
format.html { render action: "edit" }
|
63
|
+
format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# DELETE <%= route_url %>/1
|
69
|
+
# DELETE <%= route_url %>/1.json
|
70
|
+
def destroy
|
71
|
+
@<%= orm_instance.destroy %>
|
72
|
+
|
73
|
+
respond_to do |format|
|
74
|
+
format.html { redirect_to <%= index_helper %>_url }
|
75
|
+
format.json { head :no_content }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
<% end -%>
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rails/generators/resource_helpers'
|
4
|
+
|
5
|
+
module Ouvrages
|
6
|
+
module Generators
|
7
|
+
class LocalesGenerator < Rails::Generators::NamedBase
|
8
|
+
include Rails::Generators::ResourceHelpers
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
|
11
|
+
argument :locales, :type => :array, :default => %w( en fr ), :banner => "locale"
|
12
|
+
|
13
|
+
def create_locale_files
|
14
|
+
require 'httparty'
|
15
|
+
|
16
|
+
locales.each do |locale|
|
17
|
+
@locale = locale
|
18
|
+
template "#{locale}.yml", locale_filename(locale)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def locale_filename(locale)
|
25
|
+
File.join('config/locales', "#{singular_table_name}.#{locale}.yml")
|
26
|
+
end
|
27
|
+
|
28
|
+
def columns
|
29
|
+
begin
|
30
|
+
excluded_column_names = %w[]
|
31
|
+
class_name.constantize.columns.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type)}
|
32
|
+
rescue NoMethodError
|
33
|
+
class_name.constantize.fields.collect{|c| c[1]}.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type.to_s)}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
attr_reader :locale, :translated, :gender
|
38
|
+
|
39
|
+
def fetch_translation(string)
|
40
|
+
Rails.cache.fetch(["translation", string]) do
|
41
|
+
url = "http://api.wordreference.com/0.8/505fc/json/en#{locale}/#{URI.escape(string)}"
|
42
|
+
response = HTTParty.get(url)
|
43
|
+
JSON.parse(response.body)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def translate(string)
|
48
|
+
result = case locale
|
49
|
+
when "en"
|
50
|
+
case string
|
51
|
+
when "Id" then "ID"
|
52
|
+
when "Created at" then "Creation date"
|
53
|
+
when "Updated at" then "Last update"
|
54
|
+
else ""
|
55
|
+
end
|
56
|
+
when "fr"
|
57
|
+
case string
|
58
|
+
when "Id" then "Identifiant"
|
59
|
+
when "Created at" then "Date de création"
|
60
|
+
when "Updated at" then "Dernière mise à jour"
|
61
|
+
else ""
|
62
|
+
end
|
63
|
+
else
|
64
|
+
raise "Unknown locale: #{locale.inspect}"
|
65
|
+
end
|
66
|
+
result.force_encoding('ASCII-8BIT') # template is loaded as ASCII so it throws and incompatibility error
|
67
|
+
end
|
68
|
+
|
69
|
+
def plural(string)
|
70
|
+
string.pluralize
|
71
|
+
end
|
72
|
+
|
73
|
+
def capitalize_first_letter(string)
|
74
|
+
if string.present?
|
75
|
+
string[0].capitalize + string[1..-1]
|
76
|
+
else
|
77
|
+
""
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def grammar(locale, base, hint = nil)
|
82
|
+
case locale.to_s
|
83
|
+
when "code"
|
84
|
+
base
|
85
|
+
when "en"
|
86
|
+
base.gsub('_', ' ')
|
87
|
+
else
|
88
|
+
value = I18n.t("grammar.#{base}", :default => "", :locale => locale)
|
89
|
+
if value.blank?
|
90
|
+
value = ask("#{base.inspect} in #{locale}#{" (#{hint})" if hint.present?}:")
|
91
|
+
I18n.backend.store_translations(locale, {"grammar" => {base => value}})
|
92
|
+
end
|
93
|
+
value.force_encoding('ASCII-8BIT')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def resource(locale = @locale)
|
98
|
+
grammar(locale, singular_table_name)
|
99
|
+
end
|
100
|
+
|
101
|
+
def resources(locale = @locale)
|
102
|
+
grammar(locale, plural_table_name)
|
103
|
+
end
|
104
|
+
|
105
|
+
def the_resource(locale = @locale)
|
106
|
+
base = "the_#{resource(:code)}"
|
107
|
+
grammar(locale, base)
|
108
|
+
end
|
109
|
+
|
110
|
+
def of_resource(locale = @locale)
|
111
|
+
base = "of_#{resource(:code)}"
|
112
|
+
grammar(locale, base, "as in 'modification of XXX named YYY'")
|
113
|
+
end
|
114
|
+
|
115
|
+
def start_with_vowel?
|
116
|
+
%w(a e i o u ).include?(singular_table_name[0])
|
117
|
+
end
|
118
|
+
|
119
|
+
def a_resource(locale = @locale)
|
120
|
+
if start_with_vowel?
|
121
|
+
base = "an_#{resource(:code)}"
|
122
|
+
else
|
123
|
+
base = "a_#{resource(:code)}"
|
124
|
+
end
|
125
|
+
grammar(locale, base)
|
126
|
+
end
|
127
|
+
|
128
|
+
def resource_gender(locale = @locale)
|
129
|
+
grammar(locale, "#{resource(:code)}_gender", "n|m|f")
|
130
|
+
end
|
131
|
+
|
132
|
+
def grammar_values
|
133
|
+
%w( resource resources a_resource the_resource of_resource resource_gender ).map do |name|
|
134
|
+
[send(name, :code), send(name)]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def gender_select(values)
|
139
|
+
values[resource_gender.to_sym]
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
en:
|
2
|
+
activerecord:
|
3
|
+
models:
|
4
|
+
<%= singular_table_name %>: <%= capitalize_first_letter(resource) %>
|
5
|
+
attributes:
|
6
|
+
<%= singular_table_name %>:
|
7
|
+
<%- columns.each do |column| -%>
|
8
|
+
<%= column.name %>: <%= capitalize_first_letter(translate(column.name.humanize)) %>
|
9
|
+
<%- end -%>
|
10
|
+
|
11
|
+
<%= plural_table_name %>:
|
12
|
+
index:
|
13
|
+
title: List of <%= resources %>
|
14
|
+
actions: Actions
|
15
|
+
show: Show
|
16
|
+
edit: &edit Edit
|
17
|
+
destroy: &destroy Delete
|
18
|
+
confirm: &confirm <%= capitalize_first_letter(the_resource) %> will by deleted. Are you sure?
|
19
|
+
new: Add <%= a_resource %>
|
20
|
+
empty: The list is empty.
|
21
|
+
|
22
|
+
edit:
|
23
|
+
title: "Modification <%= of_resource %> %{name}"
|
24
|
+
|
25
|
+
new:
|
26
|
+
title: New <%= resource %>
|
27
|
+
|
28
|
+
form:
|
29
|
+
submit: Save <%= the_resource %>
|
30
|
+
cancel: Cancel
|
31
|
+
|
32
|
+
show:
|
33
|
+
title: "<%= capitalize_first_letter(resource) %> %{name}"
|
34
|
+
edit: *edit
|
35
|
+
destroy: *destroy
|
36
|
+
confirm: *confirm
|
37
|
+
back: Back
|
38
|
+
|
39
|
+
created: <%= capitalize_first_letter the_resource %> was successfully created.
|
40
|
+
updated: <%= capitalize_first_letter the_resource %> was successfully updated.
|
41
|
+
|
42
|
+
navigation:
|
43
|
+
<%= plural_table_name %>: <%= capitalize_first_letter(resources) %>
|
@@ -0,0 +1,48 @@
|
|
1
|
+
fr:
|
2
|
+
grammar:
|
3
|
+
<%- grammar_values.each do |name, value| -%>
|
4
|
+
<%= name %>: <%= value %>
|
5
|
+
<%- end -%>
|
6
|
+
|
7
|
+
activerecord:
|
8
|
+
models:
|
9
|
+
<%= singular_table_name %>: <%= capitalize_first_letter resource %>
|
10
|
+
attributes:
|
11
|
+
<%= singular_table_name %>:
|
12
|
+
<%- columns.each do |column| -%>
|
13
|
+
<%= column.name %>: <%= capitalize_first_letter(translate(column.name.humanize)) %>
|
14
|
+
<%- end -%>
|
15
|
+
|
16
|
+
<%= plural_table_name %>:
|
17
|
+
index:
|
18
|
+
title: Liste des <%= resources %>
|
19
|
+
actions: Actions
|
20
|
+
show: Voir
|
21
|
+
edit: &edit Modifier
|
22
|
+
destroy: &destroy Supprimer
|
23
|
+
confirm: &confirm <%= capitalize_first_letter(the_resource) %> sera <%= gender_select(m: "supprimé", f: "supprimée") %>. Êtes vous sûr ?
|
24
|
+
new: Créer <%= a_resource %>
|
25
|
+
empty: La liste est vide.
|
26
|
+
|
27
|
+
edit:
|
28
|
+
title: "Modification <%= of_resource %> %{name}"
|
29
|
+
|
30
|
+
new:
|
31
|
+
title: <%= gender_select(m: "Nouveau", f: "Nouvelle") %> <%= resource %>
|
32
|
+
|
33
|
+
form:
|
34
|
+
submit: Enregistrer <%= the_resource %>
|
35
|
+
cancel: Annuler
|
36
|
+
|
37
|
+
show:
|
38
|
+
title: "<%= capitalize_first_letter(resource) %> %{name}"
|
39
|
+
edit: *edit
|
40
|
+
destroy: *destroy
|
41
|
+
confirm: *confirm
|
42
|
+
back: Retour
|
43
|
+
|
44
|
+
created: <%= capitalize_first_letter the_resource %> a été créé.
|
45
|
+
updated: <%= capitalize_first_letter the_resource %> a été <%= gender_select(m: "modifié", f: "modifiée") %>.
|
46
|
+
|
47
|
+
navigation:
|
48
|
+
<%= plural_table_name %>: <%= capitalize_first_letter(resources) %>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Ouvrages
|
4
|
+
module Generators
|
5
|
+
class ScaffoldGenerator < ::Rails::Generators::NamedBase
|
6
|
+
def generate_controller
|
7
|
+
invoke "ouvrages:controller"
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_routes
|
11
|
+
invoke "ouvrages:routes"
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate_views
|
15
|
+
invoke "ouvrages:views"
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate_locales
|
19
|
+
invoke "ouvrages:locales"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
= bootstrap_form_for @<%= resource_name %>, :html => { :class => 'form-horizontal' } do |f|
|
2
|
+
<%- columns.each do |column| -%>
|
3
|
+
= f.<%= column.field_type %> :<%= column.name %>
|
4
|
+
<%- end -%>
|
5
|
+
|
6
|
+
.form-actions
|
7
|
+
= f.submit t('.submit'), :class => 'btn btn-primary'
|
8
|
+
= link_to t('.cancel'), <%= controller_routing_path %>_path, :class => 'btn'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
- content_for :title, t('.title')
|
2
|
+
|
3
|
+
.row
|
4
|
+
.span12
|
5
|
+
- if @<%= plural_resource_name %>.blank?
|
6
|
+
%p.alert.alert-notice= t(".empty")
|
7
|
+
- else
|
8
|
+
%table.table.table-striped
|
9
|
+
%thead
|
10
|
+
%tr
|
11
|
+
<%- columns.each do |column| -%>
|
12
|
+
%th= <%= resource_name.classify %>.human_attribute_name(:<%= column.name %>)
|
13
|
+
<%- end -%>
|
14
|
+
%th= t('.actions')
|
15
|
+
%tbody
|
16
|
+
- @<%= plural_resource_name %>.each do |<%= resource_name %>|
|
17
|
+
%tr
|
18
|
+
<%- columns.each do |column| -%>
|
19
|
+
%td= <%= resource_name %>.<%= column.name %>
|
20
|
+
<%- end -%>
|
21
|
+
%td
|
22
|
+
= link_to t('.show'), <%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-mini'
|
23
|
+
= link_to t('.edit'), edit_<%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-mini' if can? :update, <%= resource_name %>
|
24
|
+
= link_to t('.destroy'), <%= singular_controller_routing_path %>_path(<%= resource_name %>), :method => :delete, :confirm => t('.confirm'), :class => 'btn btn-mini btn-danger' if can? :destroy, <%= resource_name %>
|
25
|
+
|
26
|
+
= link_to t('.new'), new_<%= singular_controller_routing_path %>_path, :class => 'btn btn-primary' if can? :create, <%= model_name %>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
- content_for(:title, t(".title", name: @<%= resource_name %>.id))
|
2
|
+
- add_crumb content_for(:title)
|
3
|
+
|
4
|
+
.row
|
5
|
+
.span12
|
6
|
+
<%- columns.each do |column| -%>
|
7
|
+
%dl.dl-horizontal
|
8
|
+
%dt= @<%= resource_name %>.class.human_attribute_name(:<%= column.name %>)
|
9
|
+
%dd= @<%= resource_name %>.<%= column.name %>
|
10
|
+
<%- end -%>
|
11
|
+
|
12
|
+
.form-actions
|
13
|
+
= link_to t('.back'), <%= controller_routing_path %>_path, :class => 'btn'
|
14
|
+
= link_to t('.edit'), edit_<%= singular_controller_routing_path %>_path(@<%= resource_name %>), :class => 'btn' if can? :update, @<%= resource_name %>
|
15
|
+
= link_to t('.destroy'), <%= singular_controller_routing_path %>_path(@<%= resource_name %>), :method => "delete", :confirm => t('.confirm'), :class => 'btn btn-danger' if can? :destroy, @<%= resource_name %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
= simple_form_for @<%= resource_name %>, :html => { :class => 'form-horizontal' } do |f|
|
2
|
+
<%- columns.each do |column| -%>
|
3
|
+
= f.input :<%= column.name %>
|
4
|
+
<%- end -%>
|
5
|
+
<%- if ::SimpleForm::FormBuilder.instance_methods.include?(:wrapped_button) -%>
|
6
|
+
= f.button :wrapped, :cancel => <%= controller_routing_path %>_path
|
7
|
+
<%- else -%>
|
8
|
+
.form-actions
|
9
|
+
= f.button :submit, :class => 'btn-primary'
|
10
|
+
= link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn'
|
11
|
+
<%- end -%>
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/generated_attribute'
|
3
|
+
|
4
|
+
module Ouvrages
|
5
|
+
module Generators
|
6
|
+
class ViewsGenerator < ::Rails::Generators::Base
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
argument :controller_path, :type => :string
|
9
|
+
argument :model_name, :type => :string, :required => false
|
10
|
+
argument :layout, :type => :string, :default => "application",
|
11
|
+
:banner => "Specify application layout"
|
12
|
+
|
13
|
+
def initialize(args, *options)
|
14
|
+
super(args, *options)
|
15
|
+
initialize_views_variables
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_views
|
19
|
+
generate_views
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def initialize_views_variables
|
25
|
+
@base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(controller_path)
|
26
|
+
@controller_routing_path = @controller_file_path.gsub(/\//, '_')
|
27
|
+
@model_name = @controller_class_nesting + "::#{@base_name.singularize.camelize}" unless @model_name
|
28
|
+
@model_name = @model_name.camelize
|
29
|
+
end
|
30
|
+
|
31
|
+
def controller_routing_path
|
32
|
+
@controller_routing_path
|
33
|
+
end
|
34
|
+
|
35
|
+
def singular_controller_routing_path
|
36
|
+
@controller_routing_path.singularize
|
37
|
+
end
|
38
|
+
|
39
|
+
def model_name
|
40
|
+
@model_name
|
41
|
+
end
|
42
|
+
|
43
|
+
def plural_model_name
|
44
|
+
@model_name.pluralize
|
45
|
+
end
|
46
|
+
|
47
|
+
def resource_name
|
48
|
+
@model_name.demodulize.underscore
|
49
|
+
end
|
50
|
+
|
51
|
+
def plural_resource_name
|
52
|
+
resource_name.pluralize
|
53
|
+
end
|
54
|
+
|
55
|
+
def columns
|
56
|
+
begin
|
57
|
+
excluded_column_names = %w[id created_at updated_at]
|
58
|
+
@model_name.constantize.columns.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type)}
|
59
|
+
rescue NoMethodError
|
60
|
+
@model_name.constantize.fields.collect{|c| c[1]}.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type.to_s)}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def extract_modules(name)
|
65
|
+
modules = name.include?('/') ? name.split('/') : name.split('::')
|
66
|
+
name = modules.pop
|
67
|
+
path = modules.map { |m| m.underscore }
|
68
|
+
file_path = (path + [name.pluralize.underscore]).join('/')
|
69
|
+
nesting = modules.map { |m| m.camelize }.join('::')
|
70
|
+
[name, path, file_path, nesting, modules.size]
|
71
|
+
end
|
72
|
+
|
73
|
+
def generate_views
|
74
|
+
views = {
|
75
|
+
"index.html.#{ext}" => File.join('app/views', @controller_file_path, "index.html.#{ext}"),
|
76
|
+
"new.html.#{ext}" => File.join('app/views', @controller_file_path, "new.html.#{ext}"),
|
77
|
+
"edit.html.#{ext}" => File.join('app/views', @controller_file_path, "edit.html.#{ext}"),
|
78
|
+
"#{form_builder}_form.html.#{ext}" => File.join('app/views', @controller_file_path, "_form.html.#{ext}"),
|
79
|
+
"show.html.#{ext}" => File.join('app/views', @controller_file_path, "show.html.#{ext}")}
|
80
|
+
selected_views = views
|
81
|
+
options.engine == generate_erb(selected_views)
|
82
|
+
end
|
83
|
+
|
84
|
+
def generate_erb(views)
|
85
|
+
views.each do |template_name, output_path|
|
86
|
+
template template_name, output_path
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def ext
|
91
|
+
::Rails.application.config.generators.options[:rails][:template_engine] || :erb
|
92
|
+
end
|
93
|
+
|
94
|
+
def form_builder
|
95
|
+
defined?(::SimpleForm) ? 'simple_form/' : ''
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ouvrages_scaffold/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "ouvrages_scaffold"
|
8
|
+
gem.version = OuvragesScaffold::VERSION
|
9
|
+
gem.authors = ["Ouvrages"]
|
10
|
+
gem.email = ["contact@ouvrages-web.fr"]
|
11
|
+
gem.description = %q{Rails scaffold in HAML, using cancan and bootstrap}
|
12
|
+
gem.summary = %q{Rails generators that produce HAML views to be used with Bootstrap and Cancan.}
|
13
|
+
gem.homepage = "https://github.com/ouvrages/rails-cancan-bootstrap-scaffold"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'bootstrap_forms'
|
21
|
+
gem.add_dependency 'httparty'
|
22
|
+
end
|
23
|
+
|
24
|
+
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ouvrages_scaffold
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ouvrages
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bootstrap_forms
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
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'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: httparty
|
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: Rails scaffold in HAML, using cancan and bootstrap
|
47
|
+
email:
|
48
|
+
- contact@ouvrages-web.fr
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/generators/ouvrages/controller/USAGE
|
59
|
+
- lib/generators/ouvrages/controller/controller_generator.rb
|
60
|
+
- lib/generators/ouvrages/controller/templates/controller.rb
|
61
|
+
- lib/generators/ouvrages/locales/USAGE
|
62
|
+
- lib/generators/ouvrages/locales/locales_generator.rb
|
63
|
+
- lib/generators/ouvrages/locales/templates/en.yml
|
64
|
+
- lib/generators/ouvrages/locales/templates/fr.yml
|
65
|
+
- lib/generators/ouvrages/routes/USAGE
|
66
|
+
- lib/generators/ouvrages/routes/routes_generator.rb
|
67
|
+
- lib/generators/ouvrages/scaffold/scaffold_generator.rb
|
68
|
+
- lib/generators/ouvrages/views/templates/_form.html.haml
|
69
|
+
- lib/generators/ouvrages/views/templates/edit.html.haml
|
70
|
+
- lib/generators/ouvrages/views/templates/index.html.haml
|
71
|
+
- lib/generators/ouvrages/views/templates/new.html.haml
|
72
|
+
- lib/generators/ouvrages/views/templates/show.html.haml
|
73
|
+
- lib/generators/ouvrages/views/templates/simple_form/_form.html.haml
|
74
|
+
- lib/generators/ouvrages/views/views_generator.rb
|
75
|
+
- lib/ouvrages_scaffold.rb
|
76
|
+
- lib/ouvrages_scaffold/version.rb
|
77
|
+
- ouvrages_scaffold.gemspec
|
78
|
+
homepage: https://github.com/ouvrages/rails-cancan-bootstrap-scaffold
|
79
|
+
licenses: []
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.8.23
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Rails generators that produce HAML views to be used with Bootstrap and Cancan.
|
102
|
+
test_files: []
|