Module: JavyTool::Breadcrumb::Helpers
- Defined in:
- lib/javy_tool/breadcrumb.rb
Instance Method Summary collapse
-
#foot ⇒ Object
add javascript to foot.
-
#format_timestamp(ts, format = '%Y-%m-%d %H:%M') ⇒ Object
format time.
-
#head(head_identity = nil) ⇒ Object
set head description,keywords etc.
-
#link_to_add_fields(name, f, association, new_object = nil) ⇒ Object
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.
-
#notice_message ⇒ Object
display the flash messages using foundation.
- #render_body_tag ⇒ Object
- #render_breadcrumb ⇒ Object
-
#render_page_title ⇒ Object
set SITE_NAME in enviroment.rb set @page_title in controller respectively add<%= render_page_title %> in head.
- #s(html) ⇒ Object
- #yield_or_default(message, default_message = "") ⇒ Object
Instance Method Details
#foot ⇒ Object
add javascript to foot
174 175 176 177 178 |
# File 'lib/javy_tool/breadcrumb.rb', line 174 def foot content_for(:foot) do yield.html_safe end end |
#format_timestamp(ts, format = '%Y-%m-%d %H:%M') ⇒ Object
format time
180 181 182 |
# File 'lib/javy_tool/breadcrumb.rb', line 180 def (ts,format='%Y-%m-%d %H:%M') ts.strftime(format) end |
#head(head_identity = nil) ⇒ Object
set head description,keywords etc
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/javy_tool/breadcrumb.rb', line 161 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) ⇒ Object
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();
});
151 152 153 154 155 156 157 |
# File 'lib/javy_tool/breadcrumb.rb', line 151 def link_to_add_fields(name, f, association,new_object=nil) 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 link_to(name,"#",class: "add_fields",data: {association: association,content: escape_javascript(fields.html_safe)}) end |
#notice_message ⇒ Object
display the flash messages using foundation
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/javy_tool/breadcrumb.rb', line 55 def = [] flash.each do |type, | type = :info if type == :notice type = :alert if type == :error text = content_tag(:div, .html_safe, class: "alert-box #{type}") << text if end .join("\n").html_safe end |
#render_body_tag ⇒ Object
47 48 49 50 51 |
# File 'lib/javy_tool/breadcrumb.rb', line 47 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_breadcrumb ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/javy_tool/breadcrumb.rb', line 70 def return "" if .nil? || .size <= 0 prefix = "".html_safe crumb = []#.html_safe .each_with_index do |c, i| = [] << "current" if i == (.length - 1) crumb.push content_tag(:li, c ,:class => ) end return prefix + content_tag(:ul, crumb.join("").html_safe, :class => "breadcrumbs") end |
#render_page_title ⇒ Object
set SITE_NAME in enviroment.rb set @page_title in controller respectively add<%= render_page_title %> in head
42 43 44 45 |
# File 'lib/javy_tool/breadcrumb.rb', line 42 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) ⇒ Object
66 67 68 |
# File 'lib/javy_tool/breadcrumb.rb', line 66 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 = "") ⇒ Object
36 37 38 |
# File 'lib/javy_tool/breadcrumb.rb', line 36 def yield_or_default(, = "") .nil? ? : end |