Class: EmbeddedRubyProcessor
- Inherits:
-
Object
- Object
- EmbeddedRubyProcessor
- Defined in:
- lib/notroff/embedded.rb
Instance Method Summary collapse
- #clazz(name, include_body = true) ⇒ Object
- #embed(*filters, &block) ⇒ Object
- #inc(path, *filters) ⇒ Object
- #indent(delta_indent, paragraphs) ⇒ Object
- #matches(re1, re2 = re1) ⇒ Object
- #method(name, include_body = true) ⇒ Object
- #mod(name, include_body = true) ⇒ Object
- #process(paragraphs) ⇒ Object
- #process_command(ruby_expression) ⇒ Object
- #run(command, *filters) ⇒ Object
Instance Method Details
#clazz(name, include_body = true) ⇒ Object
114 115 116 |
# File 'lib/notroff/embedded.rb', line 114 def clazz(name, include_body=true) ClassFilter.new(name, include_body) end |
#embed(*filters, &block) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/notroff/embedded.rb', line 87 def (*filters, &block) paras = block.call.map {|line| line.rstrip} paras.map! {|p| Text.new(p, :type => :code)} Logger.log "EMBED: #{paras}" unless filters.empty? filters.each {|f| paras = f.process(paras)} paras = paras.find_all {|p| p[:included]} end paras end |
#inc(path, *filters) ⇒ Object
98 99 100 |
# File 'lib/notroff/embedded.rb', line 98 def inc(path, *filters) (*filters) {File.readlines(path)} end |
#indent(delta_indent, paragraphs) ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/notroff/embedded.rb', line 122 def indent(delta_indent, paragraphs) paragraphs.map do |p| if delta_indent > 0 p.string = (" " * delta_indent) + p.string elsif delta_indent < 0 p.string.sub!( ' ' * delta_indent.abs, '' ) end end paragraphs end |
#matches(re1, re2 = re1) ⇒ Object
106 107 108 |
# File 'lib/notroff/embedded.rb', line 106 def matches(re1, re2=re1) BetweenFilter.new(re1, re2) end |
#method(name, include_body = true) ⇒ Object
110 111 112 |
# File 'lib/notroff/embedded.rb', line 110 def method(name, include_body=true) MethodFilter.new(name, include_body) end |
#mod(name, include_body = true) ⇒ Object
118 119 120 |
# File 'lib/notroff/embedded.rb', line 118 def mod(name, include_body=true) ModuleFilter.new(name, include_body) end |
#process(paragraphs) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/notroff/embedded.rb', line 68 def process(paragraphs) new_paragraphs = [] paragraphs.each do |p| if p[:type] == :x Logger.log p results = process_command(p.string) new_paragraphs << results if results else new_paragraphs << p end end new_paragraphs.flatten end |
#process_command(ruby_expression) ⇒ Object
82 83 84 85 |
# File 'lib/notroff/embedded.rb', line 82 def process_command(ruby_expression) Logger.log "Ruby expression: #{ruby_expression}" lines = eval(ruby_expression, binding) end |
#run(command, *filters) ⇒ Object
102 103 104 |
# File 'lib/notroff/embedded.rb', line 102 def run(command, *filters) (*filters) {File.popen(command).readlines} end |