somatics3-generators 0.0.9 → 0.0.10
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/Rakefile +9 -1
- data/VERSION +1 -1
- data/bin/somatics +0 -0
- data/bin/somatify +0 -0
- data/lib/generators/somatics/associated/associated_generator.rb +184 -0
- data/lib/generators/somatics/associated/templates/migration.rb +11 -0
- data/lib/generators/somatics/attributes/attributes_generator.rb +8 -5
- data/lib/generators/somatics/authenticated/authenticated_generator.rb +27 -195
- data/lib/generators/somatics/authenticated/templates/partial_form.html.erb +23 -0
- data/lib/generators/somatics/authenticated_controller/authenticated_controller_generator.rb +14 -299
- data/lib/generators/somatics/authenticated_controller/templates/locales_en.yml +6 -0
- data/lib/generators/somatics/authenticated_controller/templates/locales_zh-TW.yml +6 -0
- data/lib/generators/somatics/authenticated_controller/templates/login.html.erb +10 -8
- data/lib/generators/somatics/authenticated_controller/templates/sessions_controller.rb +11 -43
- data/lib/generators/somatics/install/install_generator.rb +26 -3
- data/lib/generators/somatics/install/templates/config/locales/devise_zh-TW.yml +39 -0
- data/lib/generators/somatics/install/templates/controller_admin.rb +8 -4
- data/lib/generators/somatics/install/templates/helper_admin.rb +39 -3
- data/lib/generators/somatics/install/templates/initializer_paper_trail.rb +2 -0
- data/lib/generators/somatics/install/templates/layout_admin.html.erb +4 -4
- data/lib/generators/somatics/install/templates/lib/active_record/diff.rb +61 -0
- data/lib/generators/somatics/install/templates/lib/tasks/heroku.rake +30 -0
- data/lib/generators/somatics/install/templates/lib/tasks/svn.rake +47 -0
- data/lib/generators/somatics/install/templates/partial_versions.html.erb +56 -0
- data/lib/generators/somatics/install/templates/public/stylesheets/application.css +863 -0
- data/lib/generators/somatics/install/templates/public/stylesheets/somatics/base.css +3 -0
- data/lib/generators/somatics/install/templates/public/themes/default/stylesheets/application.css +951 -0
- data/lib/generators/somatics/install/templates/view_index.html.erb +46 -1
- data/lib/generators/somatics/scaffold/scaffold_generator.rb +0 -1
- data/lib/generators/somatics/scaffold_controller/scaffold_controller_generator.rb +31 -60
- data/lib/generators/somatics/scaffold_controller/templates/controller.rb +4 -21
- data/lib/generators/somatics/scaffold_controller/templates/view_index.html.erb +3 -4
- data/lib/generators/somatics/scaffold_controller/templates/view_show.html.erb +2 -0
- data/lib/generators/somatics/settings/settings_generator.rb +7 -3
- data/lib/generators/somatics/settings_controller/templates/controller.rb +4 -20
- data/lib/generators/somatics/settings_controller/templates/partial_form.html.erb +1 -1
- data/lib/generators/somatics/settings_controller/templates/view_index.html.erb +2 -2
- data/somatics3-generators.gemspec +28 -37
- data/templates/somatics.rb +76 -121
- metadata +70 -64
- data/lib/generators/somatics/authenticated/templates/mailer.rb +0 -25
- data/lib/generators/somatics/authenticated/templates/migration.rb +0 -26
- data/lib/generators/somatics/authenticated/templates/model.rb +0 -83
- data/lib/generators/somatics/authenticated/templates/observer.rb +0 -11
- data/lib/generators/somatics/authenticated/templates/test/mailer_test.rb +0 -31
- data/lib/generators/somatics/authenticated/templates/test/model_functional_test.rb +0 -93
- data/lib/generators/somatics/authenticated/templates/test/sessions_functional_test.rb +0 -82
- data/lib/generators/somatics/authenticated/templates/test/unit_test.rb +0 -164
- data/lib/generators/somatics/authenticated/templates/test/users.yml +0 -60
- data/lib/generators/somatics/authenticated_controller/templates/_model_partial.html.erb +0 -8
- data/lib/generators/somatics/authenticated_controller/templates/activation.erb +0 -3
- data/lib/generators/somatics/authenticated_controller/templates/authenticated_system.rb +0 -189
- data/lib/generators/somatics/authenticated_controller/templates/authenticated_test_helper.rb +0 -10
- data/lib/generators/somatics/authenticated_controller/templates/config/initializers/site_keys.rb +0 -38
- data/lib/generators/somatics/authenticated_controller/templates/controller.rb +0 -55
- data/lib/generators/somatics/authenticated_controller/templates/helper.rb +0 -91
- data/lib/generators/somatics/authenticated_controller/templates/mailer.rb +0 -25
- data/lib/generators/somatics/authenticated_controller/templates/migration.rb +0 -26
- data/lib/generators/somatics/authenticated_controller/templates/model.rb +0 -83
- data/lib/generators/somatics/authenticated_controller/templates/observer.rb +0 -11
- data/lib/generators/somatics/authenticated_controller/templates/session_helper.rb +0 -2
- data/lib/generators/somatics/authenticated_controller/templates/signup.html.erb +0 -19
- data/lib/generators/somatics/authenticated_controller/templates/signup_notification.erb +0 -8
- data/lib/generators/somatics/authenticated_controller/templates/test/mailer_test.rb +0 -31
- data/lib/generators/somatics/authenticated_controller/templates/test/model_functional_test.rb +0 -93
- data/lib/generators/somatics/authenticated_controller/templates/test/sessions_functional_test.rb +0 -82
- data/lib/generators/somatics/authenticated_controller/templates/test/unit_test.rb +0 -164
- data/lib/generators/somatics/authenticated_controller/templates/test/users.yml +0 -60
- data/lib/generators/somatics/scaffold_controller/templates/builder_index.pdf.prawn +0 -25
- data/lib/generators/somatics/settings_controller/templates/builder_index.pdf.prawn +0 -25
- data/lib/generators/somatics/settings_controller/templates/model.rb +0 -54
data/Rakefile
CHANGED
|
@@ -12,11 +12,19 @@ begin
|
|
|
12
12
|
gem.authors = ["Benjamin Wong"]
|
|
13
13
|
# gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
|
14
14
|
gem.rdoc_options += FileList['lib/**/templates/*'].to_a.collect{|f| "--exclude=#{f}" }
|
|
15
|
+
# gem.files = FileList[
|
|
16
|
+
# "README.rdoc"
|
|
17
|
+
# ]
|
|
18
|
+
# raise FileList['lib/**/templates/*'].to_a.collect{|f| "--exclude=#{f}" }.inspect
|
|
15
19
|
# gem.rdoc_options << "--exclude='lib/**/templates/*'"
|
|
16
20
|
gem.rubyforge_project = 'somatics3'
|
|
17
21
|
gem.add_dependency 'will_paginate', "~> 3.0.pre2"
|
|
18
|
-
gem.add_dependency 'prawn', "0.6.3"
|
|
19
22
|
gem.add_dependency 'json'
|
|
23
|
+
gem.add_dependency 'meta_search'
|
|
24
|
+
gem.add_dependency 'paper_trail'
|
|
25
|
+
gem.add_dependency 'tiny_mce'
|
|
26
|
+
gem.add_dependency 'devise'
|
|
27
|
+
# gem.add_dependency 'prawn', "0.6.3"
|
|
20
28
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
21
29
|
end
|
|
22
30
|
Jeweler::RubyforgeTasks.new do |rubyforge|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.10
|
data/bin/somatics
CHANGED
|
File without changes
|
data/bin/somatify
CHANGED
|
File without changes
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
require 'generators/somatics'
|
|
2
|
+
require 'rails/generators/named_base'
|
|
3
|
+
require 'rails/generators/migration'
|
|
4
|
+
|
|
5
|
+
require 'net/http'
|
|
6
|
+
require 'uri'
|
|
7
|
+
require 'json'
|
|
8
|
+
class GoogleTranslate
|
|
9
|
+
def self.t(text,to_lang = 'zh-TW')
|
|
10
|
+
uri = URI.parse('http://ajax.googleapis.com/ajax/services/language/translate')
|
|
11
|
+
JSON.parse(Net::HTTP.post_form(uri, {"q" => text, "langpair" => "en|#{to_lang}", "v" => '1.0'}).body)['responseData']['translatedText'] rescue text.humanize
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
module Somatics
|
|
17
|
+
module Generators
|
|
18
|
+
class AssociatedGenerator < Rails::Generators::NamedBase
|
|
19
|
+
extend TemplatePath
|
|
20
|
+
include Rails::Generators::Migration
|
|
21
|
+
include Rails::Generators::ResourceHelpers
|
|
22
|
+
|
|
23
|
+
argument :associated_field, :type => :string, :banner => 'associated_field_name'
|
|
24
|
+
argument :attribute, :type => :hash, :default => {"name" => "string"}, :banner => "field:type"
|
|
25
|
+
# argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
|
26
|
+
class_option :namespace, :banner => "NAME", :type => :string, :default => 'admin'
|
|
27
|
+
class_option :skip_migration, :type => :boolean, :desc => "Don't generate a migration file for this model."
|
|
28
|
+
class_option :locales, :type => :array, :banner => "LOCALE LOCALE", :default => %w( en zh-TW ),
|
|
29
|
+
:desc => "Supported Locales"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def dump_generator_attribute_names
|
|
33
|
+
generator_attribute_names = [
|
|
34
|
+
:name,
|
|
35
|
+
:singular_name,
|
|
36
|
+
:human_name,
|
|
37
|
+
:plural_name,
|
|
38
|
+
:table_name,
|
|
39
|
+
:class_name,
|
|
40
|
+
:controller_class_path,
|
|
41
|
+
:controller_file_name,
|
|
42
|
+
:attribute_name,
|
|
43
|
+
:attribute_type,
|
|
44
|
+
:associated_name,
|
|
45
|
+
:associated_singular_name,
|
|
46
|
+
:associated_human_name,
|
|
47
|
+
:associated_plural_name,
|
|
48
|
+
:associated_table_name,
|
|
49
|
+
:associated_class_name,
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
generator_attribute_names.each do |attr|
|
|
53
|
+
# puts "%-40s %s" % ["#{attr}:", self.send(attr.to_s)] # instance_variable_get("@#{attr.to_s}"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def generate_associated_scaffold
|
|
59
|
+
invoke 'somatics:scaffold', [associated_class_name, "#{attribute_name}:#{attribute_type}"], {:namespace => options[:namespace], :header => false }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def update_menu
|
|
63
|
+
# add attributes type to submenu
|
|
64
|
+
# look_for = /<li ><%= link_to 'Product', '\/admin\/products', :class => (match_controller?('products')) \? 'selected' : ''%>.*<ul>/
|
|
65
|
+
look_for = /<%=.*\/#{options.namespace}\/#{plural_name}.*%>[^<]*<ul[^>]*>/
|
|
66
|
+
inject_into_file File.join('app/views/',options.namespace, 'shared/_menu.html.erb'), :after => look_for do
|
|
67
|
+
<<-RUBY
|
|
68
|
+
|
|
69
|
+
<li><%=link_to #{class_name}.human_attribute_name(:#{associated_name}), '/#{options.namespace}/#{associated_plural_name}' %></li>
|
|
70
|
+
RUBY
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def update_show_partial
|
|
76
|
+
look_for = "</tbody>\n</table>"
|
|
77
|
+
inject_into_file File.join('app/views/',options.namespace, controller_class_path, controller_file_name, '_show.html.erb'), :before => look_for do
|
|
78
|
+
" <tr>\n <td><b><%= #{class_name}.human_attribute_name(:#{associated_name}) %></b></td>\n <td><%=h #{singular_name}.#{associated_name}_#{attribute_name}%></td>\n </tr>\n"
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def update_form_partial
|
|
83
|
+
look_for = "</tbody>\n</table>"
|
|
84
|
+
inject_into_file File.join('app/views/',options.namespace, controller_class_path, controller_file_name, '_form.html.erb'), :before => look_for do
|
|
85
|
+
" <tr>\n <td><b><%= #{class_name}.human_attribute_name(:#{associated_name}) %></b></td>\n <td><%= f.collection_select :#{associated_name}_id, #{associated_class_name}.all, :id, :#{attribute_name}, :prompt => true %></td>\n </tr>\n"
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def update_list_partial
|
|
90
|
+
# look_for = " <!-- More Sort Link Helper -->"
|
|
91
|
+
# inject_into_file File.join('app/views/',options.namespace, controller_class_path, controller_file_name, '_list.html.erb'), :after => look_for do
|
|
92
|
+
# " <th title=\"Sort by "#{attribute.name.humanize}"\"><%= sort_link_helper #{class_name}.human_attribute_name(:#{attribute.name}), '#{singular_name}', '#{attribute.name}' %></th>\n"
|
|
93
|
+
# end
|
|
94
|
+
# look_for = " <!-- More Fields -->"
|
|
95
|
+
# inject_into_file File.join('app/views/',options.namespace, controller_class_path, controller_file_name, '_list.html.erb'), :after => look_for do
|
|
96
|
+
# " <td onclick=\"link_to(<%= \"'\#{admin_#{singular_name}_path(#{singular_name})}'\" %>);\" class=\"#{attribute.name}\"><%=h #{singular_name}.#{attribute.name} %></td>\n"
|
|
97
|
+
# end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def add_attribute_to_locales
|
|
101
|
+
options[:locales].each do |locale|
|
|
102
|
+
append_file File.join('config/locales', "#{controller_file_name}_#{locale}.yml") do
|
|
103
|
+
" #{associated_name}: #{GoogleTranslate.t associated_human_name, locale}\n"
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def add_association_to_model
|
|
109
|
+
inject_into_class "app/models/#{name}.rb", class_name do
|
|
110
|
+
<<-RUBY
|
|
111
|
+
belongs_to :#{associated_name}
|
|
112
|
+
def #{associated_name}_#{attribute_name}
|
|
113
|
+
self.#{associated_name}.#{attribute_name} unless self.#{associated_name}.blank?
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def #{associated_name}_#{attribute_name}=(#{associated_name}_#{attribute_name})
|
|
117
|
+
self.#{associated_name} = #{associated_class_name}.find_by_#{attribute_name}(#{associated_name}_#{attribute_name}) || #{associated_class_name}.new(:#{attribute_name} => #{associated_name}_#{attribute_name})
|
|
118
|
+
end
|
|
119
|
+
RUBY
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
inject_into_class "app/models/#{associated_name}.rb", associated_class_name do
|
|
123
|
+
<<-RUBY
|
|
124
|
+
has_many :#{class_name}
|
|
125
|
+
RUBY
|
|
126
|
+
end rescue nil
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def migrate_attributes
|
|
130
|
+
unless options[:skip_migration]
|
|
131
|
+
invoke "migration", [%(add_#{associated_singular_name}_to_#{table_name}), "#{associated_singular_name}_id:integer"]
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
protected
|
|
136
|
+
|
|
137
|
+
#
|
|
138
|
+
# Implement the required interface for Rails::Generators::Migration.
|
|
139
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
|
140
|
+
#
|
|
141
|
+
def self.next_migration_number(dirname) #:nodoc:
|
|
142
|
+
if ActiveRecord::Base.timestamped_migrations
|
|
143
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
144
|
+
else
|
|
145
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
private
|
|
150
|
+
def attribute_name
|
|
151
|
+
attribute.keys.first
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def attribute_type
|
|
155
|
+
attribute.values.first
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def associated_name
|
|
159
|
+
name + '_' + associated_field
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def associated_singular_name
|
|
163
|
+
associated_name.singularize
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def associated_human_name
|
|
167
|
+
associated_name.humanize
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def associated_plural_name
|
|
171
|
+
associated_name.pluralize
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def associated_table_name
|
|
175
|
+
associated_name.tableize
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def associated_class_name
|
|
179
|
+
associated_name.classify
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
class <%= "add_#{migration_attribute}_to_#{migration_table_name}".camelize %> < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
add_column :<%= migration_table_name %>, :<%= migration_attribute %>, :integer
|
|
4
|
+
add_index :<%= migration_table_name %>, :<%= migration_attribute %>
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.down
|
|
8
|
+
remove_index :<%= migration_table_name %>, :<%= migration_attribute %>
|
|
9
|
+
remove_column :<%= migration_table_name %>, :<%= migration_attribute %>
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -6,9 +6,9 @@ require 'net/http'
|
|
|
6
6
|
require 'uri'
|
|
7
7
|
require 'json'
|
|
8
8
|
class GoogleTranslate
|
|
9
|
-
def self.t(text)
|
|
9
|
+
def self.t(text,to_lang = 'zh-TW')
|
|
10
10
|
uri = URI.parse('http://ajax.googleapis.com/ajax/services/language/translate')
|
|
11
|
-
JSON.parse(Net::HTTP.post_form(uri, {"q" => text, "langpair" => "en
|
|
11
|
+
JSON.parse(Net::HTTP.post_form(uri, {"q" => text, "langpair" => "en|#{to_lang}", "v" => '1.0'}).body)['responseData']['translatedText'] rescue text.humanize
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -23,6 +23,9 @@ module Somatics
|
|
|
23
23
|
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
|
24
24
|
class_option :namespace, :banner => "NAME", :type => :string, :default => 'admin'
|
|
25
25
|
class_option :skip_migration, :type => :boolean, :desc => "Don't generate a migration file for this model."
|
|
26
|
+
class_option :locales, :type => :array, :banner => "LOCALE LOCALE", :default => %w( en zh-TW ),
|
|
27
|
+
:desc => "Supported Locales"
|
|
28
|
+
|
|
26
29
|
|
|
27
30
|
def dump_generator_attribute_names
|
|
28
31
|
generator_attribute_names = [
|
|
@@ -38,7 +41,7 @@ module Somatics
|
|
|
38
41
|
]
|
|
39
42
|
|
|
40
43
|
generator_attribute_names.each do |attr|
|
|
41
|
-
puts "%-40s %s" % ["#{attr}:", self.send(attr.to_s)] # instance_variable_get("@#{attr.to_s}"
|
|
44
|
+
# puts "%-40s %s" % ["#{attr}:", self.send(attr.to_s)] # instance_variable_get("@#{attr.to_s}"
|
|
42
45
|
end
|
|
43
46
|
|
|
44
47
|
end
|
|
@@ -76,10 +79,10 @@ module Somatics
|
|
|
76
79
|
end
|
|
77
80
|
|
|
78
81
|
def update_locales
|
|
79
|
-
|
|
82
|
+
options[:locales].each do |locale|
|
|
80
83
|
append_file File.join('config/locales', "#{controller_file_name}_#{locale}.yml") do
|
|
81
84
|
attributes.inject('') do |str, attribute|
|
|
82
|
-
" #{attribute.name}: #{GoogleTranslate.t attribute.name.humanize}\n"
|
|
85
|
+
" #{attribute.name}: #{GoogleTranslate.t attribute.name.humanize, locale}\n"
|
|
83
86
|
end
|
|
84
87
|
end
|
|
85
88
|
end
|
|
@@ -1,219 +1,51 @@
|
|
|
1
1
|
require 'generators/somatics'
|
|
2
2
|
require 'rails/generators/named_base'
|
|
3
|
-
|
|
4
|
-
require 'digest/sha1'
|
|
5
|
-
require 'rails/generators/migration'
|
|
6
|
-
|
|
3
|
+
|
|
7
4
|
module Somatics
|
|
8
5
|
module Generators
|
|
9
6
|
class AuthenticatedGenerator < Rails::Generators::NamedBase
|
|
10
7
|
extend TemplatePath
|
|
11
|
-
include Rails::Generators::ResourceHelpers
|
|
12
|
-
include Rails::Generators::Migration
|
|
13
|
-
|
|
14
|
-
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
|
15
8
|
class_option :namespace, :banner => "NAME", :type => :string, :default => ''
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class_option :skip_migration, :type => :boolean, :desc => "Don't generate a migration file for this model."
|
|
19
|
-
class_option :aasm, :type => :boolean, :desc => "Works the same as stateful but uses the updated aasm gem"
|
|
20
|
-
class_option :stateful, :type => :boolean, :desc => "Builds in support for acts_as_state_machine and generatesactivation code."
|
|
21
|
-
class_option :rspec, :type => :boolean, :desc => "Generate RSpec tests and Stories in place of standard rails tests."
|
|
22
|
-
class_option :old_passwords, :type => :boolean, :desc => "Use the older password scheme"
|
|
23
|
-
class_option :include_activation, :type => :boolean, :desc => "Skip the code for a ActionMailer and its respective Activation Code through email"
|
|
24
|
-
class_option :dump_generator_attrs, :type => :boolean, :desc => "Dump Generator Attrs"
|
|
25
|
-
|
|
9
|
+
class_option :locales, :type => :array, :banner => "LOCALE LOCALE", :default => %w( en zh-TW ),
|
|
10
|
+
:desc => "Supported Locales"
|
|
26
11
|
|
|
27
|
-
def
|
|
28
|
-
|
|
29
|
-
if options.include_activation?
|
|
30
|
-
# Check for class naming collisions.
|
|
31
|
-
class_collisions "#{class_name}Mailer", "#{class_name}MailerTest", "#{class_name}Observer"
|
|
32
|
-
template "mailer.rb", File.join('app/mailers', class_path, "#{ file_name }_mailer.rb")
|
|
33
|
-
template "observer.rb", File.join('app/models', class_path, "#{ file_name }_observer.rb")
|
|
34
|
-
end
|
|
12
|
+
def create_devise_model
|
|
13
|
+
invoke 'devise'
|
|
35
14
|
end
|
|
36
15
|
|
|
37
|
-
def
|
|
38
|
-
|
|
39
|
-
|
|
16
|
+
def add_fields_to_devise_model
|
|
17
|
+
invoke "migration", [%(add_name_to_#{table_name}), "name:string"]
|
|
18
|
+
if File.exists?("app/models/#{singular_name}.rb")
|
|
19
|
+
inject_into_file "app/models/#{singular_name}.rb", :after => ":remember_me" do
|
|
20
|
+
", :name"
|
|
21
|
+
end
|
|
40
22
|
end
|
|
41
23
|
end
|
|
42
|
-
|
|
43
|
-
def dump_generator_attribute_names
|
|
44
|
-
generator_attribute_names = [
|
|
45
|
-
:table_name,
|
|
46
|
-
:file_name,
|
|
47
|
-
:class_name,
|
|
48
|
-
:sessions_controller_name,
|
|
49
|
-
:sessions_controller_class_path,
|
|
50
|
-
:sessions_controller_file_path,
|
|
51
|
-
# :sessions_controller_class_nesting,
|
|
52
|
-
# :sessions_controller_class_nesting_depth,
|
|
53
|
-
:sessions_controller_class_name,
|
|
54
|
-
:sessions_controller_singular_name,
|
|
55
|
-
:sessions_controller_plural_name,
|
|
56
|
-
:sessions_controller_routing_name, # new_session_path
|
|
57
|
-
:sessions_controller_routing_path, # /session/new
|
|
58
|
-
:sessions_controller_controller_name, # sessions
|
|
59
|
-
:sessions_controller_file_name,
|
|
60
|
-
:sessions_controller_table_name,
|
|
61
|
-
:controller_name,
|
|
62
|
-
:controller_class_path,
|
|
63
|
-
:controller_file_path,
|
|
64
|
-
# :controller_class_nesting,
|
|
65
|
-
# :controller_class_nesting_depth,
|
|
66
|
-
# :controller_class_name,
|
|
67
|
-
# :controller_singular_name,
|
|
68
|
-
:controller_plural_name,
|
|
69
|
-
:controller_routing_name, # new_user_path
|
|
70
|
-
# :controller_routing_path, # /users/new
|
|
71
|
-
# :controller_controller_name, # users
|
|
72
|
-
# :controller_file_name,
|
|
73
|
-
# :controller_singular_name,
|
|
74
|
-
# :controller_table_name,
|
|
75
|
-
# :controller_plural_name,
|
|
76
|
-
]
|
|
77
24
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
# table_name: foon_parent_foons
|
|
86
|
-
# file_name: foon
|
|
87
|
-
# class_name: FoonParent::Foon
|
|
88
|
-
# controller_name: SporkParent::Sporks
|
|
89
|
-
# controller_class_path: spork_parent
|
|
90
|
-
# controller_file_path: spork_parent/sporks
|
|
91
|
-
# controller_class_nesting: SporkParent
|
|
92
|
-
# controller_class_nesting_depth: 1
|
|
93
|
-
# controller_class_name: SporkParent::Sporks
|
|
94
|
-
# controller_singular_name: spork
|
|
95
|
-
# controller_plural_name: sporks
|
|
96
|
-
# controller_routing_name: spork
|
|
97
|
-
# controller_routing_path: spork_parent/spork
|
|
98
|
-
# controller_controller_name: sporks
|
|
99
|
-
# controller_file_name: sporks
|
|
100
|
-
# controller_table_name: sporks
|
|
101
|
-
# controller_plural_name: sporks
|
|
102
|
-
# model_controller_name: FoonParent::Foons
|
|
103
|
-
# model_controller_class_path: foon_parent
|
|
104
|
-
# model_controller_file_path: foon_parent/foons
|
|
105
|
-
# model_controller_class_nesting: FoonParent
|
|
106
|
-
# model_controller_class_nesting_depth: 1
|
|
107
|
-
# model_controller_class_name: FoonParent::Foons
|
|
108
|
-
# model_controller_singular_name: foons
|
|
109
|
-
# model_controller_plural_name: foons
|
|
110
|
-
# model_controller_routing_name: foon_parent_foons
|
|
111
|
-
# model_controller_routing_path: foon_parent/foons
|
|
112
|
-
# model_controller_controller_name: foons
|
|
113
|
-
# model_controller_file_name: foons
|
|
114
|
-
# model_controller_singular_name: foons
|
|
115
|
-
# model_controller_table_name: foons
|
|
116
|
-
# model_controller_plural_name: foons
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
protected
|
|
120
|
-
|
|
121
|
-
def namespace_class
|
|
122
|
-
# options[:namespace].classify
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def namespace_name
|
|
126
|
-
# options[:namespace].underscore
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def sessions_controller_name
|
|
130
|
-
file_name + '_sessions'
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def sessions_controller_class_path
|
|
134
|
-
class_path
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def sessions_controller_file_path
|
|
138
|
-
controller_file_path
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def sessions_controller_singular_name
|
|
142
|
-
controller_name
|
|
25
|
+
hook_for :scaffold_controller do |invoked|
|
|
26
|
+
invoke invoked, [name, "email:string", "name:string"], :namespace => 'admin'
|
|
27
|
+
if File.exists?("app/models/#{singular_name}.rb")
|
|
28
|
+
inject_into_file "app/models/#{singular_name}.rb", :after => "has_paper_trail :ignore => [:updated_at" do
|
|
29
|
+
", :encrypted_password, :password_salt, :reset_password_token, :remember_token, :remember_created_at, :sign_in_count, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip, :last_sign_in_ip"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
143
32
|
end
|
|
144
33
|
|
|
145
|
-
def
|
|
146
|
-
|
|
34
|
+
def modify_devise_model_form
|
|
35
|
+
template "partial_form.html.erb", File.join('app/views', 'admin', class_path, plural_name, "_form.html.erb"), :force => true
|
|
147
36
|
end
|
|
148
37
|
|
|
149
|
-
def
|
|
150
|
-
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def sessions_controller_routing_path
|
|
154
|
-
sessions_controller_file_path.singularize
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def sessions_controller_class_name
|
|
158
|
-
class_name + 'Session'
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def sessions_controller_controller_name
|
|
162
|
-
controller_plural_name
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
def sessions_controller_file_name
|
|
166
|
-
file_name + '_session'
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
def sessions_controller_table_name
|
|
170
|
-
controller_plural_name
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
def controller_plural_name
|
|
174
|
-
plural_name
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
def controller_routing_name
|
|
178
|
-
controller_plural_name
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
def migration_name
|
|
182
|
-
"Create#{ class_name.pluralize.gsub(/::/, '') }"
|
|
38
|
+
def create_sessions_controller
|
|
39
|
+
invoke 'somatics:authenticated_controller'
|
|
183
40
|
end
|
|
184
41
|
|
|
185
|
-
def
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
#
|
|
190
|
-
# Implement the required interface for Rails::Generators::Migration.
|
|
191
|
-
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
|
192
|
-
#
|
|
193
|
-
def self.next_migration_number(dirname) #:nodoc:
|
|
194
|
-
if ActiveRecord::Base.timestamped_migrations
|
|
195
|
-
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
196
|
-
else
|
|
197
|
-
"%.3d" % (current_migration_number(dirname) + 1)
|
|
42
|
+
def modify_devise_route
|
|
43
|
+
inject_into_file File.join('config/routes.rb'), :after => "devise_for :#{table_name}" do
|
|
44
|
+
session_controller = ((options.namespace.blank? ? [] : [options.namespace]) << "#{name}_sessions").join('/')
|
|
45
|
+
", :path => '#{options.namespace}', :controllers => {:sessions => '#{session_controller}'}"
|
|
198
46
|
end
|
|
199
47
|
end
|
|
200
|
-
|
|
201
|
-
#
|
|
202
|
-
# !! These must match the corresponding routines in by_password.rb !!
|
|
203
|
-
#
|
|
204
|
-
def secure_digest(*args)
|
|
205
|
-
Digest::SHA1.hexdigest(args.flatten.join('--'))
|
|
206
|
-
end
|
|
207
|
-
def make_token
|
|
208
|
-
secure_digest(Time.now, (1..10).map{ rand.to_s })
|
|
209
|
-
end
|
|
210
|
-
def password_digest(password, salt)
|
|
211
|
-
digest = $rest_auth_site_key_from_generator
|
|
212
|
-
$rest_auth_digest_stretches_from_generator.times do
|
|
213
|
-
digest = secure_digest(digest, salt, password, $rest_auth_site_key_from_generator)
|
|
214
|
-
end
|
|
215
|
-
digest
|
|
216
|
-
end
|
|
48
|
+
|
|
217
49
|
end
|
|
218
50
|
end
|
|
219
51
|
end
|