class NgOnRails::ViewsGenerator
Public Instance Methods
add_css()
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 69 def add_css if options[:styles] styles_path = "app/assets/stylesheets/ng_on_rails_styles.css" unless File.exist?(styles_path) puts "Adding ng_on_rails_styles.css -- <better with bootstrap and fontAwesome!>" copy_file "#{ViewsGenerator.source_root}/styles_template.css", styles_path end end end
create_jbuilder_files()
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 42 def create_jbuilder_files if options[:render_views] || options[:rails_views] unless File.exist?(index_path) puts "File[ #{index_path} ] does not exist. creating file" create_file index_path, '/ File created with NgOnRails view generator' end unless File.exist?(show_path) puts "File[ #{show_path} ] does not exist. creating file" create_file show_path, '/ File created with NgOnRails view generator' end end end
create_render_views_files()
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 28 def create_render_views_files if options[:render_views] || options[:rails_views] unless File.exist?(index_path) puts "File[ #{index_path} ] does not exist. creating file" create_file index_path, '/ File created with NgOnRails view generator' end unless File.exist?(show_path) puts "File[ #{show_path} ] does not exist. creating file" create_file show_path, '/ File created with NgOnRails view generator' end end end
generate_jbuilder_files()
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 63 def generate_jbuilder_files if options[:jbuilder] || options[:rails_views] generate "ng_on_rails:jbuilder #{full_model_name} #{jbuilder_attributes} --overwrite=#{options[:overwrite]}" end end
generate_views()
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 10 def generate_views option_template "#{ViewsGenerator.source_root}/views/#{options[:format]}/index.html.erb", "app/views/#{module_path}angular_app/#{plural_name}/index.html.#{options[:format]}", "index view" option_template "#{ViewsGenerator.source_root}/views/#{options[:format]}/show.html.erb", "app/views/#{module_path}angular_app/#{plural_name}/show.html.#{options[:format]}", "show view" option_template "#{ViewsGenerator.source_root}/views/#{options[:format]}/_show.html.erb", "app/views/#{module_path}angular_app/#{plural_name}/_show.html.#{options[:format]}", "_show partial" option_template "#{ViewsGenerator.source_root}/views/#{options[:format]}/_form.html.erb", "app/views/#{module_path}angular_app/#{plural_name}/_form.html.#{options[:format]}", "_form partial" option_template "#{ViewsGenerator.source_root}/views/#{options[:format]}/_model.html.erb", "app/views/#{module_path}angular_app/#{plural_name}/_#{resource_name}.html.#{options[:format]}", "_#{resource_name} partial" end
insert_render_views()
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 56 def insert_render_views if options[:render_views] || options[:rails_views] append_file index_path, render_index_view_template append_file show_path, render_show_view_template end end
Private Instance Methods
args(arg_string)
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 81 def args arg_string parts = arg_string.split("{") if (parts.length > 1) if !!parts[1].match(/required/) required = true else required = false end if !!parts[1].match(/skip_form/) skip_form = true else skip_form = false end if !!parts[1].match(/skip_index/) skip_index = true else skip_index = false end if !!parts[1].match(/link/) link = true else link = false end end args = parts[0].split(":") { name: args[0], type: args[1], required: required, skip_form: skip_form, skip_index: skip_index, link: link } end
index_path()
click to toggle source
TEMPLATES
# File lib/generators/ng_on_rails/views_generator.rb, line 144 def index_path @index_path ||= "app/views/#{module_path}#{plural_name}/index.html.#{options[:format]}" end
is_plural?(string)
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 116 def is_plural? string string.pluralize == string end
jbuilder_attributes()
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 152 def jbuilder_attributes ( options[:properties].map{ |prop| "#{prop.split("{")[0].split(":")[0]}" } | options[:belongs_to].map{ |model| "#{model.underscore}_id" } | options[:relationships].map{ |relationship| relationship.underscore } ).join(" ") end
relationship_url(relationship)
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 136 def relationship_url relationship "#{relationship.pluralize}/#{is_plural?(relationship) ? 'index' : 'show' }" end
render_index_view_template()
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 160 def render_index_view_template if options[:format]=="erb" puts "ERB format not yet added" elsif options[:format]=="haml" puts "HAML format not yet added" else " / / Inserted by NgOnRails view generator. / div ng-init=\"#{plural_name}=ctrl.rails.#{plural_name}\" render_view=\"true\" url=\"#{plural_name}/index\" / / / " end end
render_show_view_template()
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 180 def render_show_view_template if options[:format]=="erb" puts "ERB format not yet added" elsif options[:format]=="haml" puts "HAML format not yet added" else " / / Inserted by NgOnRails view generator. / div ng-init=\"#{resource_name}=ctrl.rails.#{resource_name}\" render_view=\"true\" url=\"#{plural_name}/show\" / / / " end end
required_string(property_hash)
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 130 def required_string property_hash if property_hash[:required] required_string = "required=\"true\"" end end
show_path()
click to toggle source
# File lib/generators/ng_on_rails/views_generator.rb, line 148 def show_path @show_path ||= "app/views/#{module_path}#{plural_name}/show.html.#{options[:format]}" end
type_to_class(type_string)
click to toggle source
VIEW HELPERS
# File lib/generators/ng_on_rails/views_generator.rb, line 124 def type_to_class type_string unless type_string.blank? ".#{type_string}" end end