Class: Hermeneutics::Html::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/hermeneutics/html.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out) ⇒ Generator

Returns a new instance of Generator.



109
110
111
112
113
# File 'lib/hermeneutics/html.rb', line 109

def initialize out
  @out = out
  @ent = Entities.new
  @nl, @ind = true, [ ""]
end

Instance Attribute Details

#assign_attributesObject

Returns the value of attribute assign_attributes.



108
109
110
# File 'lib/hermeneutics/html.rb', line 108

def assign_attributes
  @assign_attributes
end

#cdata_blockObject

Returns the value of attribute cdata_block.



108
109
110
# File 'lib/hermeneutics/html.rb', line 108

def cdata_block
  @cdata_block
end

#close_standaloneObject

Returns the value of attribute close_standalone.



108
109
110
# File 'lib/hermeneutics/html.rb', line 108

def close_standalone
  @close_standalone
end

Instance Method Details

#comment(str) ⇒ Object



194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/hermeneutics/html.rb', line 194

def comment str
  if str =~ /\A.*\z/ then
    brace_comment do
      @out << " " << str << " "
    end
  else
    brace_comment do
      brk
      out_brk str
      do_ind
    end
  end
end

#doctype(*args) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/hermeneutics/html.rb', line 181

def doctype *args
  brace true do
    @out << "!DOCTYPE"
    args.each { |x|
      @out << " "
      if x =~ /\W/ then
        @out << '"' << (@ent.encode x) << '"'
      else
        @out << x
      end
    }
  end
end

#encodingObject



114
115
116
117
118
119
# File 'lib/hermeneutics/html.rb', line 114

def encoding
  case @out
    when IO then @out.external_encoding||Encoding.default_external
    else         @out.encoding
  end
end

#file_pathObject



120
121
122
123
# File 'lib/hermeneutics/html.rb', line 120

def file_path
  @out.path
rescue NoMethodError
end

#pi_tag(tag, attrs = nil) ⇒ Object

Processing Instruction



170
171
172
173
174
175
176
177
178
179
180
# File 'lib/hermeneutics/html.rb', line 170

def pi_tag tag, attrs = nil
  tag = tag.to_s
  brace true do
    begin
      @out << "?" << tag
      mkattrs attrs
    ensure
      @out << " ?"
    end
  end
end

#plain(str) ⇒ Object



124
125
126
127
# File 'lib/hermeneutics/html.rb', line 124

def plain str
  do_ind
  @out << (@ent.encode str)
end

#tag(tag, type, attrs = nil) ⇒ Object

nls 0 = no newline 1 = newline after 2 = newline after both 3 = and advance indent 4 = Block without any indent



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/hermeneutics/html.rb', line 134

def tag tag, type, attrs = nil
  tag = tag.to_s
  nls = type & 0xf
  if (type & 0x10).nonzero? then
    brace nls>0 do
      @out << tag
      mkattrs attrs
      @out << " /" if @close_standalone
    end
  else
    begin
      brk if nls>1
      brace nls>1 do
        @out << tag
        mkattrs attrs
      end
      if nls >3 then
        verbose_block yield
      else
        indent_if nls>2 do
          if block_given? then
            r = yield
            plain r if String === r
          end
        end
      end
    ensure
      brk if nls>1
      brace nls>0 do
        @out << "/" << tag
      end
    end
  end
  nil
end

#verbose_block(str) ⇒ Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/hermeneutics/html.rb', line 207

def verbose_block str
  if @cdata_block then
    @out << "/* "
    brace false do
      @out << "![CDATA["
      @out << " */" << $/
      @out << str
      @out << $/ << "/* "
      @out << "]]"
    end
    @out << " */"
  else
    out_brk str
  end
end