Module: Zafu::Process::HTML

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#html_tagObject

Returns the value of attribute html_tag.



4
5
6
# File 'lib/zafu/process/html.rb', line 4

def html_tag
  @html_tag
end

#html_tag_paramsObject

Returns the value of attribute html_tag_params.



4
5
6
# File 'lib/zafu/process/html.rb', line 4

def html_tag_params
  @html_tag_params
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/zafu/process/html.rb', line 4

def name
  @name
end

#sub_doObject

Returns the value of attribute sub_do.



4
5
6
# File 'lib/zafu/process/html.rb', line 4

def sub_do
  @sub_do
end

Instance Method Details

#after_process(text) ⇒ Object



56
57
58
59
60
# File 'lib/zafu/process/html.rb', line 56

def after_process(text)
  res = @markup.wrap(super)
  @markup = @markup_bak
  res
end

#before_processObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/zafu/process/html.rb', line 35

def before_process
  return unless super
  @markup.done = false
  unless @markup.tag
    if @markup.tag = @params.delete(:tag)
      @markup.params = {}
      [:id, :class].each do |k|
        next unless @params[k]
        @markup.params[k] = @params.delete(k)
      end
    end
  end
  # Translate dynamic params such as <tt>class='#{visitor.lang}'</tt> in the context
  # of the current parser
  @markup.compile_params(self)

  # [each] is run many times with different roles. Some of these change html_tag_params.
  @markup_bak = @markup.dup
  true
end

#empty?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/zafu/process/html.rb', line 31

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

#include_part(obj) ⇒ Object

Pass the caller’s ‘html_tag’ and ‘html_tag_params’ to the included part.



23
24
25
26
27
28
29
# File 'lib/zafu/process/html.rb', line 23

def include_part(obj)
  obj.html_tag = @markup.tag || obj.html_tag
  obj.html_tag_params = !@markup.params.empty? ? @markup.params : obj.html_tag_params
  @markup.tag = nil
  @markup.params = {}
  super(obj)
end

#inspectObject



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/zafu/process/html.rb', line 62

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}]#{render_html_tag($2)}[/#{$3}]"
    end
  end
  res
end

#r_formObject



123
124
125
126
127
128
129
130
131
132
# File 'lib/zafu/process/html.rb', line 123

def r_form
  res   = "<#{@markup.tag}#{params_to_html(@params)}"
  @markup.done = true
  inner = expand_with
  if inner == ''
    res + "/>"
  else
    res + ">#{inner}"
  end
end

#r_ignoreObject Also known as: r_



75
76
77
78
# File 'lib/zafu/process/html.rb', line 75

def r_ignore
  @markup.done = true
  ''
end

#r_inputObject



145
146
147
148
149
150
151
152
153
154
# File 'lib/zafu/process/html.rb', line 145

def r_input
  res   = "<#{@markup.tag}#{params_to_html(@params)}"
  @markup.done = true
  inner = expand_with
  if inner == ''
    res + "/>"
  else
    res + ">#{inner}"
  end
end

#r_rename_assetObject



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
118
119
120
121
# File 'lib/zafu/process/html.rb', line 82

def r_rename_asset
  return expand_with 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 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[key]
  if src && src[0..0] != '/' && src[0..6] != 'http://'
    @params[key] = helper.send(:template_url_for_asset, :src => src, :base_path => @options[:base_path], :type => type)
  end

  res   = "<#{@markup.tag}#{params_to_html(@params)}"
  @markup.done = true
  inner = expand_with
  if inner == ''
    res + "/>"
  else
    res + ">#{inner}"
  end
end

#r_selectObject



134
135
136
137
138
139
140
141
142
143
# File 'lib/zafu/process/html.rb', line 134

def r_select
  res   = "<#{@markup.tag}#{params_to_html(@params)}"
  @markup.done = true
  inner = expand_with
  if inner == ''
    res + "></#{@markup.tag}>"
  else
    res + ">#{inner}"
  end
end

#r_textareaObject



156
157
158
159
160
161
162
163
164
165
# File 'lib/zafu/process/html.rb', line 156

def r_textarea
  res   = "<#{@markup.tag}#{params_to_html(@params)}"
  @markup.done = true
  inner = expand_with
  if inner == ''
    res + "/>"
  else
    res + ">#{inner}"
  end
end

#replace_with(new_obj) ⇒ Object

Replace the ‘original’ element in the included template with our new version.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/zafu/process/html.rb', line 7

def replace_with(new_obj)
  super
  html_tag_params    = new_obj.html_tag_params
  [:class, :id].each do |sym|
    html_tag_params[sym] = new_obj.params[sym] if new_obj.params.include?(sym)
  end
  @markup.tag = new_obj.html_tag || @markup.tag
  @markup.params.merge!(html_tag_params)
  if new_obj.params[:method]
    @method   = new_obj.params[:method] if new_obj.params[:method]
  elsif new_obj.sub_do
    @method = 'void'
  end
end