class Pulitzer::PostTypeGenerator
Public Instance Methods
build_post_type_files()
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 51 def build_post_type_files abort("Couldn't find Pulitzer::PostType named #{post_type_name}") unless post_type.is_a? Pulitzer::PostType kind_method = "build_#{kind}" send kind_method end
Protected Instance Methods
action_name()
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 119 def action_name file_name.gsub(/-/,'_') end
all_element_types(ptv)
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 155 def all_element_types(ptv) ptv.all_element_types.sort_by(&:sort_order).map do |et| GeneratorElementType.new(et) end end
arity()
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 161 def arity return @arity if @arity.present? @arity = post_type.plural? ? 'plural' : 'singleton' puts "Generating files for a #{@arity} post type" @arity end
arrangements(ptv)
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 151 def arrangements(ptv) ptv.arrangement_styles.map{|l| l.view_file_name} end
build_partial()
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 81 def build_partial post_type_versions.each do |ptv| empty_directory partial_path(ptv) arrangements(ptv).each do |file_name| copy_file "post_view.html.erb", layout_path(ptv,file_name) inject_into_file layout_path(ptv,file_name), before: "<%# END Auto-generated by Pulitzer %>", force: false do <<-BEGIN_COMMENT <!-- BEGIN #{layout_short_path(ptv,file_name)} --> BEGIN_COMMENT end ptv.post_type_content_element_types.each do |ptcet| content_element_name = ptcet.label optional = !ptcet.required? inject_into_file layout_path(ptv,file_name), before: "<%# END Auto-generated by Pulitzer %>", force: false do content = '' if optional content += " <% if cms_content_present? partial.content_element('#{content_element_name}') %>\n " end content += " <%= render_cms_element partial.content_element('#{content_element_name}') %>\n" if optional content += " <% end %>\n" end content end end inject_into_file layout_path(ptv,file_name), before: "<%# END Auto-generated by Pulitzer %>", force: false do <<-BEGIN_COMMENT <!-- END #{layout_short_path(ptv,file_name)} --> BEGIN_COMMENT end end end end
build_template()
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 59 def build_template route get_route inject_into_file File.join(Rails.root,'config','routes.rb'), after: "namespace :#{Pulitzer.preview_namespace} do\n", force: false do "\t\t#{get_route}\n" end post_type_versions.each do |ptv| copy_file "post_view.html.erb", view_path(ptv) all_element_types(ptv).each do |el_type| inject_into_file view_path(ptv), before: "<%# END Auto-generated by Pulitzer %>", force: false do el_type.injection_content end end end inject_into_file File.join(Rails.root,'app','controllers', "#{Pulitzer.public_controller}_controller.rb"), after: "#Pulitzer Generated Actions\n", force: false do get_controller_action('active') end inject_into_file File.join(Rails.root,'app','controllers', Pulitzer.preview_namespace, "#{Pulitzer.public_controller}_controller.rb"), after: "#Pulitzer Generated Actions\n", force: false do get_controller_action('preview') end end
file_name()
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 115 def file_name parameterize(post_type_name) end
get_controller_action(context)
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 180 def get_controller_action(context) <<-PACTION def #{action_name} @post, @post_type_version = get_#{context}_post('#{post_type_name}') render template: pulitzer_view_path(@post_type_version.version_number) end PACTION end
get_route()
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 168 def get_route send "#{arity}_route" end
kind()
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 143 def kind post_type.kind end
layout_path(ptv,file_name)
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 131 def layout_path(ptv,file_name) File.join(Rails.root,'app','views', Pulitzer.partial_folder, action_name, "v_#{ptv.version_number}", "_#{file_name}.html.erb") end
layout_short_path(ptv,file_name)
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 127 def layout_short_path(ptv,file_name) File.join(action_name, "v_#{ptv.version_number}", "_#{file_name}.html.erb") end
partial_path(ptv)
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 147 def partial_path(ptv) File.join(Rails.root,'app','views', Pulitzer.partial_folder, action_name, "v_#{ptv.version_number}") end
plural_route()
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 172 def plural_route "get '#{file_name}/:slug' => '#{Pulitzer.public_controller}##{action_name}', as: '#{action_name}'" end
post_type()
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 135 def post_type Pulitzer::PostType.named(post_type_name) end
post_type_versions()
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 139 def post_type_versions post_type.post_type_versions end
singleton_route()
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 176 def singleton_route "get '#{file_name}' => 'pages##{action_name}', as: '#{action_name}'" end
view_path(ptv)
click to toggle source
# File lib/generators/pulitzer/post_type_generator.rb, line 123 def view_path(ptv) File.join(Rails.root,'app','views', Pulitzer.public_controller, action_name, "v_#{ptv.version_number}.html.erb") end