lib/active_text/base.rb in active_text-0.0.2 vs lib/active_text/base.rb in active_text-0.0.3

- old
+ new

@@ -10,10 +10,12 @@ options[:eol] ||= '\n' options[:context_lines] ||= 3 options[:comment] ||= /\/\// options[:context] ||= "(^(?:#{options[:comment]}\s@.*#{options[:eol]}){#{options[:context_lines]}})" @options = options + + scan end def update_attributes(args) args.each do |k, v| send(k) # Instantiate it, so it will exist in @variables @@ -27,10 +29,22 @@ @text.gsub!(/^\$#{key}: .+;/, %Q($#{key}: #{var.value};)) end @text end + def attributes + @variables + end + protected + + # scans though the text and instantiates all the variables in @variables + def scan + @text.each do |string| + string =~ /^\${1}([a-zA-Z0-9_]+):.+;/ + @variables[$1] = ActiveText::Variable.new($1, context_of($1), @options[:comment]) if $1 + end + end # Whenever a variable is requested for, it falls into this. def method_missing(method_name) if method_name.to_s =~ /[\w]+/ context = context_of(method_name)