Class: Quarry::Markup
- Defined in:
- lib/quarry/markup.rb,
lib/quarry/markup/step.rb,
lib/quarry/markup/after.rb,
lib/quarry/markup/macro.rb,
lib/quarry/markup/table.rb,
lib/quarry/markup/before.rb,
lib/quarry/markup/header.rb,
lib/quarry/markup/comment.rb
Overview
:nodoc:
Defined Under Namespace
Classes: After, Before, Comment, Header, Macro, Step, Table
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(file) ⇒ Markup
constructor
A new instance of Markup.
- #parse ⇒ Object
- #parse_section(text, lineno) ⇒ Object
- #to_script ⇒ Object
Constructor Details
#initialize(file) ⇒ Markup
Returns a new instance of Markup.
19 20 21 22 23 |
# File 'lib/quarry/markup.rb', line 19 def initialize(file) @file = file @steps = [] parse end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
15 16 17 |
# File 'lib/quarry/markup.rb', line 15 def file @file end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
16 17 18 |
# File 'lib/quarry/markup.rb', line 16 def steps @steps end |
Instance Method Details
#description ⇒ Object
78 79 80 |
# File 'lib/quarry/markup.rb', line 78 def description File.basename(file) end |
#parse ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/quarry/markup.rb', line 26 def parse lineno = 0 text = '' File.open(file, 'r') do |f| f.readlines.each_with_index do |line, lineno| case line when /^\s*$/ parse_section(text, lineno) text = '' else text << line end end end end |
#parse_section(text, lineno) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/quarry/markup.rb', line 43 def parse_section(text, lineno) return if text.strip == '' case text when /\A[-=].*?$/, /[-=]\s*\Z/ #text << line steps << Header.new(self, text, lineno) when /^\s+/ case last = steps.last when Step, Macro last.code << "\n\n#{text.rstrip}" when Comment if last.text =~ /\A([A-Z]{1,9})[:]/ #if macro = Macro.types.find{ |m| m.match?(last.text) } type = Markup.const_get($1.capitalize) step = type.new(self, text, lineno, :comment=>last.text, :before=>@before, :after=>@after) case step when Before @before = step when After @after = step end steps << step else steps << Step.new(self, text, lineno, :before=>@before, :after=>@after) end else raise "never here" steps << Step.new(self, text, lineno, :before=>@before, :after=>@after) end else steps << Comment.new(self, text, lineno) end end |
#to_script ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/quarry/markup.rb', line 83 def to_script script = [] Dir.chdir(File.dirname(file)) do steps.each do |step| script << step.to_script end end script.join("\n\n") end |