Class: Htmler

Inherits:
Object
  • Object
show all
Defined in:
lib/htmler/base.rb,
lib/htmler/version.rb

Constant Summary collapse

VERSION =
"0.0.20"

Instance Method Summary collapse

Constructor Details

#initializeHtmler

Returns a new instance of Htmler.



4
5
6
# File 'lib/htmler/base.rb', line 4

def initialize
  @_result = ''
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/htmler/base.rb', line 12

def method_missing(name, *args, &block)
  if args[0].class == Hash
    arguments = " " << args[0].map { |k, v| "#{k}=\"#{v}\"" }.join(' ')
  else
    arguments = ""
  end
  
  @_result += "<#{name}#{arguments}>"
  if block_given?
    _return = block.call
    @_result +=  _return.to_s unless _return.nil?
  end
  @_result += "</#{name}>"
  
  # print the temporary stack
  # puts "> #{@_result}"
  
  nil
  
end

Instance Method Details

#compile(input) ⇒ Object



33
34
35
# File 'lib/htmler/base.rb', line 33

def compile(input)
  instance_eval(input)
end

#compile_file(name) ⇒ Object



37
38
39
40
# File 'lib/htmler/base.rb', line 37

def compile_file(name)
  #puts File.new(name).readlines.map { |i| i.to_s }.join
  instance_eval(File.new(name).readlines.map { |i| i.to_s }.join)
end

#to_htmlObject



8
9
10
# File 'lib/htmler/base.rb', line 8

def to_html
  @_result
end