Module: CommonHelper
- Defined in:
- lib/rails_ext/action_view/common_helper.rb
Instance Method Summary collapse
-
#has_content_for?(name) ⇒ Boolean
Has content for ‘content_for’.
-
#initialize_js_commons ⇒ Object
Initialize JavaScripts variables, needed to rails_ext.js works properly.
-
#js(*args, &block) ⇒ Object
Escape JS.
-
#prepend_to(name, content = nil, &block) ⇒ Object
Prepends content to ‘content_for’.
-
#tidy_html(html) ⇒ Object
def autohide # request.format == Mime::JS ? ‘hidden’ : ” Thread.current ? ‘hidden’ : ” end.
-
#wrap_content_for(name, &block) ⇒ Object
Wraps content for ‘content_for’.
Instance Method Details
#has_content_for?(name) ⇒ Boolean
Has content for ‘content_for’
29 30 31 32 |
# File 'lib/rails_ext/action_view/common_helper.rb', line 29 def has_content_for? name ivar = "@content_for_#{name}" !instance_variable_get(ivar).blank? end |
#initialize_js_commons ⇒ Object
Initialize JavaScripts variables, needed to rails_ext.js works properly.
3 4 5 6 |
# File 'lib/rails_ext/action_view/common_helper.rb', line 3 def initialize_js_commons javascript_tag %{\ $.authenticity_token = "#{form_authenticity_token}";} end |
#js(*args, &block) ⇒ Object
Escape JS
35 36 37 |
# File 'lib/rails_ext/action_view/common_helper.rb', line 35 def js *args, &block escape_javascript *args, &block end |
#prepend_to(name, content = nil, &block) ⇒ Object
Prepends content to ‘content_for’
9 10 11 12 13 14 15 16 |
# File 'lib/rails_ext/action_view/common_helper.rb', line 9 def prepend_to name, content = nil, &block ivar = "@content_for_#{name}" content = capture(&block) if block_given? content ||= "" stored_content = instance_variable_get(ivar) || "" instance_variable_set(ivar, content + stored_content) nil end |
#tidy_html(html) ⇒ Object
def autohide
# request.format == Mime::JS ? 'hidden' : ''
Thread.current[:autohide] ? 'hidden' : ''
end
def render_hidden *args, &block
begin
Thread.current[:autohide] = true
render *args, &block
ensure
Thread.current[:autohide] = false
end
end
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rails_ext/action_view/common_helper.rb', line 66 def tidy_html html require 'tidy' Tidy.path = '/usr/lib/libtidy.dylib' # depends on platform! = { :indent => true, :char_encoding => 'utf8', :wrap => 0, :output_xhtml => true, :show_errors => 6, :show_warnings => true, :tab_size => 2, :vertical_space => true, :new_inline_tags => "script" } Tidy.open do |tidy| xml = tidy.clean(html) # puts " Tidy Messages:" # puts tidy.errors # puts tidy.diagnostics # puts # xml.gsub(">\n</script>", "></script>") # tidy makes it newline xml end end |
#wrap_content_for(name, &block) ⇒ Object
Wraps content for ‘content_for’
19 20 21 22 23 24 25 26 |
# File 'lib/rails_ext/action_view/common_helper.rb', line 19 def wrap_content_for name, &block block.should_not! :be_nil ivar = "@content_for_#{name}" content = capture(instance_variable_get(ivar) || "", &block) instance_variable_set(ivar, content || "") nil end |