Module: MarkdownRubyDocumentation::TemplateParser::Parsing

Included in:
ClassLevelComment, CommentMacros
Defined in:
lib/markdown_ruby_documentation/template_parser/parsing.rb

Instance Method Summary collapse

Instance Method Details

#extract_dsl_comment(comment_string) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/markdown_ruby_documentation/template_parser/parsing.rb', line 54

def extract_dsl_comment(comment_string)
  if (v = when_start_and_end(comment_string))
    v
  elsif (x = when_only_start(comment_string))
    x
  else
    ""
  end
end

#extract_dsl_comment_from_method(method) ⇒ Object



74
75
76
# File 'lib/markdown_ruby_documentation/template_parser/parsing.rb', line 74

def extract_dsl_comment_from_method(method)
  extract_dsl_comment strip_comment_hash(ruby_class_meth_comment(method))
end

#insert_method_name(string, method) ⇒ Object



35
36
37
# File 'lib/markdown_ruby_documentation/template_parser/parsing.rb', line 35

def insert_method_name(string, method)
  string.gsub("__method__", "'#{method.to_s}'")
end

#parse_erb(str, method) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/markdown_ruby_documentation/template_parser/parsing.rb', line 4

def parse_erb(str, method)
  filename, lineno = ruby_class_meth_source_location(method)
  adjusted_lineno  = (lineno - ruby_class_meth_comment(method).split("\n").count-1)
  ruby_class.module_eval("  def self.get_binding\n    self.send(:binding)\n  end\n  RUBY\n  ruby_class.send(:define_singleton_method, :current_method) do\n    method\n  end\n\n  ruby_class.send(:define_singleton_method, :output_object) do\n    output_object\n  end\n\n  ruby_class.send(:define_singleton_method, :load_path) do\n    load_path\n  end\n\n  ruby_class.extend(CommentMacros)\n\n  erb          = ERB.new(str, nil, \"-\")\n\n  erb.lineno   = adjusted_lineno if erb.respond_to?(:lineno)\n  erb.filename = filename if erb.respond_to?(:filename)\n  erb.result(ruby_class.get_binding)\nrescue => e\n  raise e.class, e.message, [\"\#{filename}:\#{adjusted_lineno}:in `\#{method.name}'\", *e.backtrace]\nend\n", __FILE__, __LINE__+1)

#ruby_class_meth_comment(method) ⇒ Object



43
44
45
46
47
48
# File 'lib/markdown_ruby_documentation/template_parser/parsing.rb', line 43

def ruby_class_meth_comment(method)
  method.context.public_send(method.type, method.name).comment

rescue MethodSource::SourceNotFoundError => e
  raise e.class, "#{ method.context}#{method.type_symbol}#{method.name}, \n#{e.message}"
end

#ruby_class_meth_source_location(method) ⇒ Object



50
51
52
# File 'lib/markdown_ruby_documentation/template_parser/parsing.rb', line 50

def ruby_class_meth_source_location(method)
  method.context.public_send(method.type, method.name).source_location
end

#strip_comment_hash(str) ⇒ Object



39
40
41
# File 'lib/markdown_ruby_documentation/template_parser/parsing.rb', line 39

def strip_comment_hash(str)
  str.gsub(/^#[\s]?/, "")
end

#when_only_start(comment_string) ⇒ Object



69
70
71
72
# File 'lib/markdown_ruby_documentation/template_parser/parsing.rb', line 69

def when_only_start(comment_string)
  v = /#{START_TOKEN}\n((.|\n)*)/.match(comment_string)
  v.try!(:captures).try!(:first)
end

#when_start_and_end(comment_string) ⇒ Object



64
65
66
67
# File 'lib/markdown_ruby_documentation/template_parser/parsing.rb', line 64

def when_start_and_end(comment_string)
  v = /#{START_TOKEN}\n((.|\n)*)#{END_TOKEN}/.match(comment_string)
  v.try!(:captures).try!(:first)
end