Class: YDocx::Builder
- Inherits:
-
Object
- Object
- YDocx::Builder
- Includes:
- MarkupMethod
- Defined in:
- lib/ydocx/builder.rb,
lib/ydocx/templates/fachinfo.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#container ⇒ Object
Returns the value of attribute container.
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#files ⇒ Object
Returns the value of attribute files.
-
#indecies ⇒ Object
Returns the value of attribute indecies.
-
#references ⇒ Object
Returns the value of attribute references.
-
#style ⇒ Object
writeonly
Sets the attribute style.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #build_html ⇒ Object
- #build_xml ⇒ Object
- #init ⇒ Object
-
#initialize(contents) ⇒ Builder
constructor
A new instance of Builder.
Methods included from MarkupMethod
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
#block ⇒ Object
Returns the value of attribute block.
11 12 13 |
# File 'lib/ydocx/builder.rb', line 11 def block @block end |
#container ⇒ Object
Returns the value of attribute container.
11 12 13 |
# File 'lib/ydocx/builder.rb', line 11 def container @container end |
#contents ⇒ Object
Returns the value of attribute contents.
11 12 13 |
# File 'lib/ydocx/builder.rb', line 11 def contents @contents end |
#files ⇒ Object
Returns the value of attribute files.
11 12 13 |
# File 'lib/ydocx/builder.rb', line 11 def files @files end |
#indecies ⇒ Object
Returns the value of attribute indecies.
11 12 13 |
# File 'lib/ydocx/builder.rb', line 11 def indecies @indecies end |
#references ⇒ Object
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
11 12 13 |
# File 'lib/ydocx/builder.rb', line 11 def style=(value) @style = value end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/ydocx/builder.rb', line 11 def title @title end |
Instance Method Details
#build_html ⇒ Object
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. :charset => 'utf-8' doc.title @title doc.style { doc << style } if @style } doc.body { doc << body } } end builder.to_html.gsub(/\n/, '') end |
#build_xml ⇒ Object
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 |
#init ⇒ Object
28 29 |
# File 'lib/ydocx/builder.rb', line 28 def init end |