module GettextI18nRailsJs::Parser::Javascript
Public Instance Methods
target?(file)
click to toggle source
# File lib/gettext_i18n_rails_js/parser/javascript.rb, line 35 def target?(file) [ ".js", ".coffee" ].include? ::File.extname(file) end
Protected Instance Methods
arg_regex()
click to toggle source
# File lib/gettext_i18n_rails_js/parser/javascript.rb, line 74 def arg_regex # # * Some whitespace # * A token inside the argument list, like a single quoted string # * Double quote string, both support escapes # * A number, variable name, or called function lik: 33, foo, Foo.bar() # * More whitespace # / \s* ( '(?:[^'\\]|\\.)*?'| "(?:[^"\\]|\\.)*?"| [a-zA-Z0-9_\.()]*? ) \s* /x end
collect_for(value) { |function, arguments, idx + 1| ... }
click to toggle source
# File lib/gettext_i18n_rails_js/parser/javascript.rb, line 44 def collect_for(value) ::File.open(value) do |f| f.each_line.each_with_index.collect do |line, idx| line.scan(invoke_regex).collect do |function, arguments| yield(function, arguments, idx + 1) end end.inject([], :+).compact end end
invoke_regex()
click to toggle source
# File lib/gettext_i18n_rails_js/parser/javascript.rb, line 54 def invoke_regex # # * Matches the function call grouping the method used (__, n__, N__) # * A parenthesis to start the arguments to the function. # * There may be many arguments to the same function call # * Then the last, or only argument to the function call. # * Function call closing parenthesis # / (\b[snN]?#{gettext_function}) \( ( (#{arg_regex},)* #{arg_regex} )? \) /x end