Class: JtplParser

Inherits:
Object
  • Object
show all
Defined in:
lib/jtplparser.rb

Class Method Summary collapse

Class Method Details

.begin_end_strings(block_name) ⇒ Object



24
25
26
# File 'lib/jtplparser.rb', line 24

def self.begin_end_strings(block_name)
  ["<!-- BEGIN: #{block_name.strip} -->", "<!-- END: #{block_name.strip} -->"]
end

.blocks(string) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jtplparser.rb', line 5

def self.blocks(string)
  blocks = string.strip.scan(/(\<!\s*--)(.*?)(--\s*\>)/m)

  unless blocks == []
    blocks = blocks.map  do |b|
      {:name => b[1].strip.gsub("BEGIN: ", "").gsub("END: ", "") }
    end

    # eliminate invalid named blocks
    blocks = blocks.select {|b| b[:name].gsub(/\w*/, '').empty? }
  end

  blocks.uniq
end

.variables(string) ⇒ Object



20
21
22
# File 'lib/jtplparser.rb', line 20

def self.variables(string)
  string.strip.scan(/\{.*?\}/).map {|s| s.gsub('{', '').gsub('}', '') }
end