Module: Zafu::Process::HTML

Defined in:
lib/zafu/process/html.rb

Class Method Summary collapse

Instance Method Summary collapse

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_paramsObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/zafu/process/html.rb', line 51

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

Returns:

  • (Boolean)


47
48
49
# File 'lib/zafu/process/html.rb', line 47

def empty?
  super && @markup.params == {} && @markup.tag.nil?
end

#include_part(obj) ⇒ Object

Pass the caller’s ‘markup’ to the included part.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/zafu/process/html.rb', line 32

def include_part(obj)
  if @markup.tag
    obj.markup = @markup.dup
  end
  @markup.tag = nil

  if sub_do
    obj.method = @blocks.first.method
    obj.params = @blocks.first.params
  elsif params[:method]
    obj.method = params[:method]
  end
  super(obj)
end

#inspectObject

def restore_markup

# restore @markup
@markup = @markup_bak

end



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/zafu/process/html.rb', line 74

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_ignoreObject



87
88
89
90
# File 'lib/zafu/process/html.rb', line 87

def r_ignore
  @markup.done = true
  ''
end

#r_rename_assetObject



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
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/zafu/process/html.rb', line 92

def r_rename_asset
  return expand_with unless @markup.tag
  case @markup.tag
  when 'link'
    key = :href
    return parser_error("Missing 'rel' parameter.") unless rel = @params[:rel]
    return parser_error("Missing 'href' parameter.") unless @params[:href]
    if rel.downcase == 'stylesheet'
      type = :stylesheet
    else
      type = :link
    end
  when 'style'
    @markup.done = true
    return expand_with.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..7] != '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)

  expand_with
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
27
28
29
# 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
  else
    # Steal 'class' param
    @markup.steal_html_params_from(new_obj.params)
  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

#steal_and_eval_html_params_for(markup, params) ⇒ Object



131
132
133
134
135
136
# File 'lib/zafu/process/html.rb', line 131

def steal_and_eval_html_params_for(markup, params)
  markup.steal_keys.each do |key|
    next unless value = params.delete(key)
    append_markup_attr(markup, key, value)
  end
end

#wrap_html(text) ⇒ Object



64
65
66
67
# File 'lib/zafu/process/html.rb', line 64

def wrap_html(text)
  compile_html_params
  @markup.wrap(text)
end