module JavyTool::Breadcrumb::Helpers
Public Instance Methods
foot() { || ... }
click to toggle source
add javascript to foot
# File lib/javy_tool/breadcrumb.rb, line 177 def foot content_for(:foot) do yield.html_safe end end
format_timestamp(ts,format='%Y-%m-%d %H:%M')
click to toggle source
format time
# File lib/javy_tool/breadcrumb.rb, line 183 def format_timestamp(ts,format='%Y-%m-%d %H:%M') ts.strftime(format) end
head(head_identity=nil) { || ... }
click to toggle source
set head description,keywords etc
# File lib/javy_tool/breadcrumb.rb, line 164 def head(head_identity=nil) content_for(:head) do case head_identity when "description" "<meta name=\"description\" content=\"#{yield}\" />\n" when "keywords" "<meta name=\"keywords\" content=\"#{yield}\" />\n" else yield end.html_safe end end
link_to_add_fields(name, f, association,new_object=nil,options={})
click to toggle source
add nested object to the parent form by ajax parameters: name: link title f: form_for's f association: association object example: <%=link_to_add_fields(“Add Cycle”,f,:pipgame_cycles,f.object.pipgame_cycles.new(:item_type => “App”,:position => “cycle_img”)) %> this method will render _pipgame_cycle_fields.html.erb file like
<div class="fields" rel="need_upload"> <p> <%= f.label :img_src %><br /> <%= f.hidden_field :img_src,:class=>"web_img_src" %> <%= f.hidden_field :item_type %> <%= f.hidden_field :position %> <%= f.hidden_field :_destroy %> <%= link_to_function "remove", "remove_fields(this)" %> </p> </div>
and you need add javascript like following:
function remove_fields(link) { $(link).prev("input[type=hidden]").val("1"); $(link).closest(".fields").hide(); } function add_fields(link, association, content) { var new_id = new Date().getTime(); var regexp = new RegExp("new_" + association, "g"); var con = content.replace(regexp, new_id); //console.log(con); $(link).parent().before(con); } deprecated in rails4 need to fix the link_to_founction Fixed: Need change the association_fields like following: <div class="fields" rel="need_upload"> <p> <%= f.label :img_src %><br /> <%= f.hidden_field :img_src,:class=>"web_img_src" %> <%= f.hidden_field :item_type %> <%= f.hidden_field :position %> <%= f.hidden_field :_destroy %> <%= link_to "remove_fields", "#" %> </p> </div> Need add code to application.js like following: $(document).bind("click",".add_fields",function(e){ e.preventDefault(); var _this = $(this); var new_id = new Date().getTime(); var regexp = new RegExp("new_" + _this.data("association"), "g"); var con = _this.data("content").replace(regexp, new_id); $(this).parent().before(con); }).bind("click",".remove_fields",function(e){ e.preventDefault(); var _this = $(this); _this.prev("input[type=hidden]").val("1"); _this.closest(".fields").hide(); });
# File lib/javy_tool/breadcrumb.rb, line 153 def link_to_add_fields(name, f, association,new_object=nil,options={}) new_object ||= f.object.class.reflect_on_association(association).klass.new() fields = f.fields_for(association, new_object, child_index: "new_#{association}") do |builder| render(association.to_s.singularize + "_fields", :f => builder) end options.merge!(data: {association: association,content: escape_javascript(fields.html_safe)},class: "add_fields") link_to(name,"#",options) end
notice_message(cls: 'alert-box')
click to toggle source
display the flash messages using foundation
# File lib/javy_tool/breadcrumb.rb, line 56 def notice_message(cls: 'alert-box') flash_messages = [] flash.each do |type, message| next if message.nil? type = :info if type == :notice type = :alert if type == :error text = content_tag(:div, message.html_safe, class: "#{cls} #{type}") flash_messages << text if message end flash_messages.join("\n").html_safe end
render_body_tag()
click to toggle source
# File lib/javy_tool/breadcrumb.rb, line 48 def render_body_tag class_attribute = ["#{controller_name}-controller","#{action_name}-action"].join(" ") id_attribute = (@body_id)? " id=\"#{@body_id}-page\"" : "" raw(%Q[ <body#{id_attribute} class="#{class_attribute}"> ]) end
render_page_title()
click to toggle source
set SITE_NAME in enviroment.rb set @page_title in controller respectively add<%= render_page_title
%> in head
# File lib/javy_tool/breadcrumb.rb, line 43 def render_page_title title = @page_title ? "#{@page_title}_#{SITE_NAME}" : SITE_NAME rescue "SITE_NAME" content_tag("title", title, nil, false) end
s(html)
click to toggle source
# File lib/javy_tool/breadcrumb.rb, line 68 def s(html) sanitize( html, :tags => %w(table thead tbody tr td th ol ul li div span font img sup sub br hr a pre p h1 h2 h3 h4 h5 h6), :attributes => %w(id class style src href size color) ) end
yield_or_default(message, default_message = "")
click to toggle source
# File lib/javy_tool/breadcrumb.rb, line 37 def yield_or_default(message, default_message = "") message.nil? ? default_message : message end