Class: YDocx::Builder

Inherits:
Object
  • Object
show all
Includes:
MarkupMethod
Defined in:
lib/ydocx/builder.rb,
lib/ydocx/templates/fachinfo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MarkupMethod

#markup

Constructor Details

#initialize(contents) ⇒ Builder

Returns a new instance of Builder.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ydocx/builder.rb', line 13

def initialize(contents)
  @contents = contents
  @container = {}
  @indecies = []
  @references = []
  @block = :div
  @block_class = nil
  @files = Pathname.new('.')
  @style = false
  @title = ''
  init
  if block_given?
    yield self
  end
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



11
12
13
# File 'lib/ydocx/builder.rb', line 11

def block
  @block
end

#containerObject

Returns the value of attribute container.



11
12
13
# File 'lib/ydocx/builder.rb', line 11

def container
  @container
end

#contentsObject

Returns the value of attribute contents.



11
12
13
# File 'lib/ydocx/builder.rb', line 11

def contents
  @contents
end

#filesObject

Returns the value of attribute files.



11
12
13
# File 'lib/ydocx/builder.rb', line 11

def files
  @files
end

#indeciesObject

Returns the value of attribute indecies.



11
12
13
# File 'lib/ydocx/builder.rb', line 11

def indecies
  @indecies
end

#referencesObject

Returns the value of attribute references.



11
12
13
# File 'lib/ydocx/builder.rb', line 11

def references
  @references
end

#style=(value) ⇒ Object

Sets the attribute style

Parameters:

  • value

    the value to set the attribute style to.



11
12
13
# File 'lib/ydocx/builder.rb', line 11

def style=(value)
  @style = value
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/ydocx/builder.rb', line 11

def title
  @title
end

Instance Method Details

#build_htmlObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ydocx/builder.rb', line 30

def build_html
  contents = @contents
  body = compile(contents, :html)
  if @container.has_key?(:content)
    body = build_tag(@container[:tag], body, @container[:attributes])
  end
  if before = build_before_content
    body = build_tag(before[:tag], before[:content], before[:attributes]) << body
  end
  if after = build_after_content
    body << build_tag(after[:tag], after[:content], after[:attributes])
  end
  builder = Nokogiri::HTML::Builder.new do |doc|
    doc.html {
      doc.head {
        doc.meta :charset => 'utf-8'
        doc.title @title
        doc.style { doc << style } if @style
      }
      doc.body { doc << body }
    }
  end
  builder.to_html.gsub(/\n/, '')
end

#build_xmlObject



54
55
56
57
58
59
60
61
62
# File 'lib/ydocx/builder.rb', line 54

def build_xml
  paragraphs = compile(@contents, :xml)
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.document {
      xml.paragraphs { xml << paragraphs }
    }
  end
  builder.to_xml(:indent => 0, :encoding => 'utf-8').gsub(/\n/, '')
end

#initObject



28
29
# File 'lib/ydocx/builder.rb', line 28

def init
end