Class: ExtParser

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

Class Method Summary collapse

Class Method Details

.parse(text) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/extjsml/parser.rb', line 5

def self.parse(text)
  begin
    matcher = /^(\w+)(?:(?:#([\w\-]+))?(?:\.([\w\-]+))?)?(?:(?:@\{(.*)\}))*$/
    res = matcher.match text 
    xtype = res[1] 
    id = res[2]
    classes = res[3].sub("_"," ") unless res[3].nil?
    options = {}
    options.merge! :id => id unless id.nil?
    options.merge! :cls => classes unless classes.nil?

    config = res[4]

    if not config.nil? and config.strip != ""
      config = config.strip!.gsub(/\)\s+:/, ")$$:").split("$$")
      config.map! do |c|
        c.gsub!(/\(/,": ")
        c.gsub!(/\)/," ")
      end
      config = YAML.load(config * "\n")
      options.merge! config
    end
  rescue Exception => e
    puts "error near #{text}: #{e.message}"
    abort()
  end
  # TODO validate xtype
  [ xtype, options ]
end