Class: Dryml::DrymlDoc::Taglib

Inherits:
Object
  • Object
show all
Includes:
classy_module do def comment_intro comment && comment =~ /(.*?)^#/m ? $1 : comment end def comment_rest comment && comment[comment_intro.length.classy_module do def comment_intro comment && comment =~ /(.*?)^#/m ? $1 : comment end def comment_rest comment && comment[comment_intro.length..-1] end %w(comment comment_intro comment_rest).each do |m| class_eval "def #{m}_html; Maruku.new(#{m}).to_html.gsub(/&/, '&'); end" end end
Defined in:
lib/dryml/dryml_doc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(home, filename, name = nil) ⇒ Taglib

Returns a new instance of Taglib.



33
34
35
36
37
# File 'lib/dryml/dryml_doc.rb', line 33

def initialize(home, filename, name=nil)
  @name = name || filename.sub(/.dryml$/, '')[home.length+1..-1]
  @filename = filename
  parse_file(filename)
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



45
46
47
# File 'lib/dryml/dryml_doc.rb', line 45

def doc
  @doc
end

#filenameObject (readonly)

Returns the value of attribute filename.



45
46
47
# File 'lib/dryml/dryml_doc.rb', line 45

def filename
  @filename
end

#nameObject (readonly)

Returns the value of attribute name.



45
46
47
# File 'lib/dryml/dryml_doc.rb', line 45

def name
  @name
end

#sourceObject (readonly)

Returns the value of attribute source.



45
46
47
# File 'lib/dryml/dryml_doc.rb', line 45

def source
  @source
end

#tag_defsObject (readonly)

Returns the value of attribute tag_defs.



45
46
47
# File 'lib/dryml/dryml_doc.rb', line 45

def tag_defs
  @tag_defs
end

Instance Method Details

#commentObject



47
48
49
50
51
52
53
54
55
# File 'lib/dryml/dryml_doc.rb', line 47

def comment
  first_node = doc[0][0]
  if first_node.is_a?(REXML::Comment)
    doc.restore_erb_scriptlets(first_node.to_s.strip)
  elsif first_node.to_s.strip.starts_with?("[![DRYML-ERB")
    text = doc.restore_erb_scriptlets(first_node.to_s.strip)
    text.match(/<%#(.*?)%>/m)[1] rescue nil
  end
end

#parse_file(filename) ⇒ Object



39
40
41
42
43
# File 'lib/dryml/dryml_doc.rb', line 39

def parse_file(filename)
  @source = File.read(filename)
  @doc = Dryml::Parser::Document.new(File.read(filename), filename)
  parse_tag_defs
end