erb_parser 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/erb_parser.rb +15 -2
  2. metadata +2 -2
data/lib/erb_parser.rb CHANGED
@@ -6,8 +6,21 @@ require 'erb_parser/erb_tag'
6
6
  require 'erb_parser/xml_transformer'
7
7
 
8
8
  module ErbParser
9
- def self.parse(str)
10
- ParsedErb.new TreetopRunner.run(str)
9
+ def self.parse(str, options = {})
10
+ result = ParsedErb.new TreetopRunner.run(str)
11
+
12
+ if options[:transform]
13
+ result.tokens.map do |elem|
14
+ case elem
15
+ when String
16
+ elem
17
+ when ErbTag
18
+ options[:transform].call(elem)
19
+ end
20
+ end.join
21
+ else
22
+ result
23
+ end
11
24
  end
12
25
 
13
26
  # Takes a string representing an XML document or fragment. Finds every ERB tag in the
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erb_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-26 00:00:00.000000000 Z
12
+ date: 2014-02-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: treetop