Module: Stratagem::Model::ParseUtil
- Included in:
- Component::Base, Component::View
- Defined in:
- lib/stratagem/model/parse_util.rb
Constant Summary collapse
- RUBY_REGEX =
/\<\%(.*?\%)\>/m
- RUBY_OUTPUT_REGEX =
/\<\%\=(.*?\%)\>/m
Class Method Summary collapse
- .find_classes(parse_tree) ⇒ Object
-
.qualified_class_name(parse_tree) ⇒ Object
assumes a single class in the tree will return the qualified class name (modules + class).
Instance Method Summary collapse
- #gsub_ruby_blocks(view_erb) ⇒ Object
- #ruby_blocks(view_erb) ⇒ Object
- #ruby_output_blocks(view_erb) ⇒ Object
Class Method Details
.find_classes(parse_tree) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/stratagem/model/parse_util.rb', line 6 def self.find_classes(parse_tree) class_names = qualified_class_name(parse_tree) class_names.map {|name| clazz = Kernel begin name.constantize rescue p $! nil end } end |
.qualified_class_name(parse_tree) ⇒ Object
assumes a single class in the tree will return the qualified class name (modules + class)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/stratagem/model/parse_util.rb', line 21 def self.qualified_class_name(parse_tree) qualified_names = [] path = [] parse_tree.walk {|parent,i,subi,node| path.pop while (path.include?(parent) && (path.last != parent)) path << parent unless path.last == parent qualified_names << (path.clone << node) if node.kind_of?(RedParse::ClassNode) true } qualified_names.map! {|qualified_name| qualified_name.select {|node| node.kind_of?(RedParse::ModuleNode) || node.kind_of?(RedParse::ClassNode)}.map {|node| begin node.name.ident rescue node.name end }.join('::') } qualified_names end |
Instance Method Details
#gsub_ruby_blocks(view_erb) ⇒ Object
55 56 57 58 59 |
# File 'lib/stratagem/model/parse_util.rb', line 55 def gsub_ruby_blocks(view_erb) view_erb.gsub(RUBY_REGEX) {|ruby| yield ruby } end |
#ruby_blocks(view_erb) ⇒ Object
49 50 51 52 53 |
# File 'lib/stratagem/model/parse_util.rb', line 49 def ruby_blocks(view_erb) view_erb.scan(RUBY_REGEX).flatten.map {|line| line.strip.gsub(/^\=\s*/, '').gsub(/\%$/, '').gsub(/\-$/, '') } end |
#ruby_output_blocks(view_erb) ⇒ Object
43 44 45 46 47 |
# File 'lib/stratagem/model/parse_util.rb', line 43 def ruby_output_blocks(view_erb) view_erb.scan(RUBY_OUTPUT_REGEX).flatten.map {|line| line.strip.gsub(/^\=\s*/, '').gsub(/\%$/, '').gsub(/\-$/, '') } end |