Class: Openehr::Generators::ScaffoldGenerator
- Inherits:
-
ArchetypedBase
- Object
- Rails::Generators::Base
- ArchetypedBase
- Openehr::Generators::ScaffoldGenerator
show all
- Defined in:
- lib/generators/openehr/scaffold/scaffold_generator.rb
Instance Method Summary
collapse
#initialize
Instance Method Details
#append_locale_route ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/generators/openehr/scaffold/scaffold_generator.rb', line 46
def append_locale_route
unless File.exist? 'config/routes.rb'
template 'routes.rb', File.join("config", 'routes.rb')
end
inject_into_file 'config/routes.rb',
" resources :#{controller_file_path}\n",
:after => "Application.routes.draw do\n"
end
|
#append_set_locale ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/generators/openehr/scaffold/scaffold_generator.rb', line 89
def append_set_locale
unless File.exist? 'app/controllers/application_controller.rb'
template 'application_controller.rb', File.join("app/controllers", 'application_controller.rb')
end
inject_into_file 'app/controllers/application_controller.rb', <<LOCALE, :after => "class ApplicationController < ActionController::Base\n"
before_action :set_locale
def set_locale
I18n.locale = params[:locale] || session[:locale] || I18n.default_locale
session[:locale] = I18n.locale
end
LOCALE
end
|
#create_root_folder ⇒ Object
18
19
20
|
# File 'lib/generators/openehr/scaffold/scaffold_generator.rb', line 18
def create_root_folder
empty_directory File.join("app/views", controller_file_path)
end
|
#generate_edit ⇒ Object
30
31
32
|
# File 'lib/generators/openehr/scaffold/scaffold_generator.rb', line 30
def generate_edit
generate_view "edit.html.erb"
end
|
37
38
39
|
# File 'lib/generators/openehr/scaffold/scaffold_generator.rb', line 37
def generate_form
generate_view "_form.html.erb"
end
|
#generate_index ⇒ Object
22
23
24
|
# File 'lib/generators/openehr/scaffold/scaffold_generator.rb', line 22
def generate_index
generate_view "index.html.erb"
end
|
#generate_layout_stylesheet ⇒ Object
70
71
72
|
# File 'lib/generators/openehr/scaffold/scaffold_generator.rb', line 70
def generate_layout_stylesheet
template 'layout.css.scss', File.join('app/assets/stylesheets', 'layout.css.scss')
end
|
#generate_new ⇒ Object
34
35
36
|
# File 'lib/generators/openehr/scaffold/scaffold_generator.rb', line 34
def generate_new
generate_view 'new.html.erb'
end
|
#generate_show ⇒ Object
26
27
28
|
# File 'lib/generators/openehr/scaffold/scaffold_generator.rb', line 26
def generate_show
generate_view "show.html.erb"
end
|
#insert_locale_swither ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/generators/openehr/scaffold/scaffold_generator.rb', line 55
def insert_locale_swither
unless File.exist? 'app/views/layouts/application.html.erb'
template 'application.html.erb', File.join('app/views/layouts', 'application.html.erb')
end
inject_into_file 'app/views/layouts/application.html.erb', <<SWITCHER, :after => "<body>\n"
<div id="banner">
<%= form_tag '', :method => 'get', class: 'locale' do %>
<%= select_tag 'locale',
options_for_select(LANGUAGES, I18n.locale.to_s),
onchange: 'this.form.submit()' %>
<% end %>
</div>
SWITCHER
end
|
#insert_uncountable_inflection ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/generators/openehr/scaffold/scaffold_generator.rb', line 74
def insert_uncountable_inflection
inflections_file_path = 'config/initializers/inflections.rb'
unless File.exist? inflections_file_path
empty_directory File.join('config/initializers')
template 'inflections.rb', File.join('config/initializers', 'inflections.rb')
else
append_to_file inflections_file_path, <<INFLECTION
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.uncountable %w( )
end
INFLECTION
end
insert_into_file inflections_file_path, model_name, :after => "inflect.uncountable %w( "
end
|