Module: Zafu::Process::HTML
- Defined in:
- lib/zafu/process/html.rb
Class Method Summary collapse
Instance Method Summary collapse
- #compile_html_params ⇒ Object
- #empty? ⇒ Boolean
-
#include_part(obj) ⇒ Object
Pass the caller’s ‘markup’ to the included part.
-
#inspect ⇒ Object
def restore_markup # restore @markup @markup = @markup_bak end.
- #r_ignore ⇒ Object
- #r_rename_asset ⇒ Object
-
#replace_with(new_obj) ⇒ Object
Replace the ‘original’ element in the included template with our new version.
- #wrap_html(text) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/zafu/process/html.rb', line 4 def self.included(base) base.wrap :wrap_html end |
Instance Method Details
#compile_html_params ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/zafu/process/html.rb', line 41 def compile_html_params return if @markup.done unless @markup.tag if @markup.tag = @params.delete(:tag) @markup.steal_html_params_from(@params) end end # Translate dynamic params such as <tt>class='#{visitor.lang}'</tt> in the context # of the current parser @markup.compile_params(self) end |
#empty? ⇒ Boolean
37 38 39 |
# File 'lib/zafu/process/html.rb', line 37 def empty? super && @markup.params == {} && @markup.tag.nil? end |
#include_part(obj) ⇒ Object
Pass the caller’s ‘markup’ to the included part.
29 30 31 32 33 34 35 |
# File 'lib/zafu/process/html.rb', line 29 def include_part(obj) if @markup.tag obj.markup = @markup.dup end @markup.tag = nil super(obj) end |
#inspect ⇒ Object
def restore_markup
# restore @markup
@markup = @markup_bak
end
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/zafu/process/html.rb', line 64 def inspect @markup.done = false res = super if @markup.tag if res =~ /\A\[(\w+)(.*)\/\]\Z/m res = "[#{$1}#{$2}]<#{@markup.tag}/>[/#{$1}]" elsif res =~ /\A\[([^\]]+)\](.*)\[\/(\w+)\]\Z/m res = "[#{$1}]#{@markup.wrap($2)}[/#{$3}]" end end res end |
#r_ignore ⇒ Object
77 78 79 80 |
# File 'lib/zafu/process/html.rb', line 77 def r_ignore @markup.done = true '' end |
#r_rename_asset ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/zafu/process/html.rb', line 82 def r_rename_asset return unless @markup.tag case @markup.tag when 'link' key = :href if @params[:rel].downcase == 'stylesheet' type = :stylesheet else type = :link end when 'style' @markup.done = true return .gsub(/url\(('|")(.*?)\1\)/) do if $2[0..6] == 'http://' $& else quote = $1 new_src = helper.send(:template_url_for_asset, :base_path=>@options[:base_path], :src => $2) "url(#{quote}#{new_src}#{quote})" end end else key = :src type = @markup.tag.to_sym end src = @params.delete(key) if src && src[0..6] != 'http://' new_value = helper.send(:template_url_for_asset, :src => src, :base_path => @options[:base_path], :type => type) @markup.params[key] = new_value.blank? ? src : new_value end @markup.steal_html_params_from(@params) end |
#replace_with(new_obj) ⇒ Object
Replace the ‘original’ element in the included template with our new version.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/zafu/process/html.rb', line 9 def replace_with(new_obj) super # [self = original_element]. Replace @markup with content of the new_obj (<ul do='with'>...) if new_obj.markup.tag @markup.tag = new_obj.markup.tag end @markup.params.merge!(new_obj.markup.params) # We do not have to merge dyn_params since these are compiled before processing (and we are in # the pre-processor) if new_obj.params[:method] @method = new_obj.params[:method] elsif new_obj.sub_do @method = 'void' end end |
#wrap_html(text) ⇒ Object
54 55 56 57 |
# File 'lib/zafu/process/html.rb', line 54 def wrap_html(text) compile_html_params @markup.wrap(text) end |