Skip to content
Browse files

translate exception: f.submit "foo"

  • Loading branch information...
1 parent c3c6d63 commit 7a83ebbbcc96892912542b8f9f5c349fb74fad19 @shaiguitar committed Sep 30, 2013
View
28 lib/haml-i18n-extractor/extraction/finder/exception_finder.rb
@@ -3,20 +3,38 @@ module I18n
class Extractor
class ExceptionFinder
- def initialize(text)
- @text = text
- end
-
LINK_TO_REGEX_DOUBLE_Q = /link_to\s*\(?\s*["](.*?)["]\s*,\s*(.*)\)?/
LINK_TO_REGEX_SINGLE_Q = /link_to\s*\(?\s*['](.*?)[']\s*,\s*(.*)\)?/
LINK_TO_BLOCK_FORM_SINGLE_Q = /link_to\s*\(?['](.*?)[']\)?.*\sdo\s*$/
LINK_TO_BLOCK_FORM_DOUBLE_Q = /link_to\s*\(?["](.*?)["]\)?.*\sdo\s*$/
LINK_TO_NO_QUOTES = /link_to\s*\(?([^'"]*?)\)?.*/
+ FORM_SUBMIT_BUTTON_SINGLE_Q = /[a-z]\.submit\s?['](.*?)['].*$/
+ FORM_SUBMIT_BUTTON_DOUBLE_Q = /[a-z]\.submit\s?["](.*?)["].*$/
+
# this class simply returns text except for anything that matches these regexes.
# returns first match.
EXCEPTION_MATCHES = [ LINK_TO_BLOCK_FORM_DOUBLE_Q, LINK_TO_BLOCK_FORM_SINGLE_Q,
- LINK_TO_REGEX_DOUBLE_Q, LINK_TO_REGEX_SINGLE_Q , LINK_TO_NO_QUOTES ]
+ LINK_TO_REGEX_DOUBLE_Q, LINK_TO_REGEX_SINGLE_Q , LINK_TO_NO_QUOTES,
+ FORM_SUBMIT_BUTTON_SINGLE_Q, FORM_SUBMIT_BUTTON_DOUBLE_Q]
+
+
+ def initialize(text)
+ @text = text
+ end
+
+ def self.could_match_script?(txt)
+ # want to match:
+ # = 'foo'
+ # = "foo"
+ # = link_to 'bla'
+ #
+ # but not match:
+ # = ruby_var = 2
+ scanner = StringScanner.new(txt)
+ scanner.scan(/\s+/)
+ scanner.scan(/['"]/) || EXCEPTION_MATCHES.any? {|regex| txt.match(regex) }
+ end
def find
ret = @text
View
2 lib/haml-i18n-extractor/extraction/finder/text_finder.rb
@@ -55,7 +55,7 @@ def tag(line)
def script(line)
txt = line[:value][:text]
- if could_match_script?(txt)
+ if ExceptionFinder.could_match_script?(txt)
FinderResult.new(:script, ExceptionFinder.new(txt).find)
else
FinderResult.new(:script, "")
View
12 lib/haml-i18n-extractor/helpers.rb
@@ -49,18 +49,6 @@ def link_to?(txt)
txt.match(/link_to/) || txt.match(/^\s*['"]/) # %element= 'foo'
end
- def could_match_script?(txt)
- # want to match:
- # = 'foo'
- # = "foo"
- # = link_to 'bla'
- #
- # but not match:
- # = ruby_var = 2
- scanner = StringScanner.new(txt)
- scanner.scan(/\s+/)
- scanner.scan(/['"]/) || scanner.scan(/link_to/)
- end
end
module Highline
View
3 test/exception_finder_test.rb
@@ -19,7 +19,8 @@ class ExceptionFinderTest < MiniTest::Unit::TestCase
%{link_to("TEXT"), role: 'button', data: {toggle: 'dropdown'} do} => "TEXT",
%{link_to "TEXT", role: 'button', data: {toggle: 'dropdown'} do} => "TEXT",
%{link_to pending_account_invoices_path(account) do} => "",
- %{link_to(pending_account_invoices_path(account),"http://random")} => ""
+ %{link_to(pending_account_invoices_path(account),"http://random")} => "",
+ %{f.submit "Close This Month (cannot be undone)", :class => 'btn btn-primary'} => "Close This Month (cannot be undone)"
}
def test_it_finds_text_pretty_simply
View
2 test/support/ex2.output.haml
@@ -17,7 +17,7 @@
- if @billing_month.open?
- if @billing_month.past_cutoff && (@billable_invoices == @active_invoices)
= form_for @billing_month, :url => close_admin_billing_month_url(@billing_month), :method => "POST" do |f|
- = f.submit "Close This Month (cannot be undone)", :class => 'btn btn-primary'
+ = f.submit t('.close_this_month_cannot_be_und'), :class => 'btn btn-primary'
- else
%p
= t('.billing_month_cannot_be_closed')

0 comments on commit 7a83ebb

Please sign in to comment.
Something went wrong with that request. Please try again.