Module: Fortitude::Widget::TagLikeMethods
- Extended by:
- ActiveSupport::Concern
- Included in:
- Fortitude::Widget
- Defined in:
- lib/fortitude/widget/tag_like_methods.rb
Constant Summary collapse
- CDATA_START =
"<![CDATA[".freeze
- CDATA_END =
"]]>".freeze
Instance Method Summary collapse
-
#cdata(s = nil, &block) ⇒ Object
PUBLIC API.
-
#tag_comment(s) ⇒ Object
PUBLIC API.
-
#tag_javascript(content = nil, &block) ⇒ Object
PUBLIC API.
Instance Method Details
#cdata(s = nil, &block) ⇒ Object
PUBLIC API
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/fortitude/widget/tag_like_methods.rb', line 76 def cdata(s = nil, &block) if s raise ArgumentError, "You can only pass literal text or a block, not both" if block components = s.split("]]>") if components.length > 1 components.each_with_index do |s, i| this_component = s this_component = ">#{this_component}" if i > 0 this_component = "#{this_component}]]" if i < (components.length - 1) cdata(this_component) end else tag_rawtext CDATA_START tag_rawtext s tag_rawtext CDATA_END end else tag_rawtext CDATA_START yield tag_rawtext CDATA_END end end |
#tag_comment(s) ⇒ Object
PUBLIC API
29 30 31 32 33 34 35 36 37 |
# File 'lib/fortitude/widget/tag_like_methods.rb', line 29 def tag_comment(s) fo = self.class.format_output @_fortitude_rendering_context.needs_newline! if fo raise ArgumentError, "You cannot pass a block to a comment" if block_given? tag_rawtext "<!-- " tag_rawtext comment_escape(s) tag_rawtext " -->" @_fortitude_rendering_context.needs_newline! if fo end |
#tag_javascript(content = nil, &block) ⇒ Object
PUBLIC API
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fortitude/widget/tag_like_methods.rb', line 40 def tag_javascript(content = nil, &block) args = if content.kind_of?(Hash) [ self.class.doctype.default_javascript_tag_attributes.merge(content) ] elsif content if block raise ArgumentError, "You can't supply JavaScript content both via text and a block" else block = lambda { tag_rawtext content } [ self.class.doctype.default_javascript_tag_attributes.dup ] end else [ self.class.doctype.default_javascript_tag_attributes.dup ] end actual_block = block if self.class.doctype.needs_cdata_in_javascript_tag? actual_block = lambda do tag_rawtext "\n//#{CDATA_START}\n" block.call tag_rawtext "\n//#{CDATA_END}\n" end end @_fortitude_rendering_context.with_indenting_disabled do script(*args, &actual_block) end end |