haml-i18n-extractor 0.5.8 → 0.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -40,70 +40,111 @@ This should be a before and after picture of using this lib, whether using the n
40
40
  - Before running (old haml):
41
41
 
42
42
  <pre>
43
- shai@comp ~/p/project master $ cat app/views/admin/notifications/index.html.haml
44
- %h1 Consumer Notifications
45
-
46
- .nav= will_paginate(@consumer_notifications)
47
- %table.themed{cellspacing: 0}
48
- %thead
49
- %tr
50
- %th.first Type
51
- %th Identifier
52
- %th Data
53
- %th Success
54
- %th Reported To
55
- - @consumer_notifications.each do |cn|
56
- %tr
57
- %td.type= cn.notification.type
58
- %td.identifier= cn.notification.identifier
59
- %td.data= cn.notification.data
60
- %td.success= cn.success
61
- %td.reported_to= cn.reported_to
62
- .nav= will_paginate(@consumer_notifications)
43
+
44
+ shai@comp $ cat /tmp/foo.haml
45
+
46
+ = render :partial => "layouts/adminnav", :locals => {:account => nil }
47
+ .row
48
+ .admin.span12
49
+ %h1
50
+ Billing Month
51
+ = @billing_month.display_name
52
+
53
+ %h3
54
+ All Invoices Billable?
55
+ %span{:style => (@billable_invoices == @active_invoices) ? "color: #090" : "color: #900"}
56
+ = "#{@billable_invoices} out of #{@active_invoices}"
57
+ %h3
58
+ 24 hours past end of billing month?
59
+ %span{:style => (@billing_month.past_cutoff) ? "color: #090" : "color: #900"}
60
+ = @billing_month.past_cutoff
61
+
62
+ - if @billing_month.open?
63
+ - if @billing_month.past_cutoff && (@billable_invoices == @active_invoices)
64
+ = form_for @billing_month, :url => close_admin_billing_month_url(@billing_month), :method => "POST" do |f|
65
+ = f.submit "Close This Month (cannot be undone)", :class => 'btn btn-primary'
66
+ - else
67
+ %p
68
+ Billing Month cannot be closed yet.
69
+ %p
70
+ Closing the billing month will mark all the invoices as "Posted".
71
+ %p
72
+ After closing you will need to do a payment run to charge all the affected customers for the amounts due in posted invoices.
73
+ - elsif @billing_month.closing?
74
+ Month is currently closing (reload to check if it's done)
75
+ - elsif @billing_month.closed?
76
+ Month is closed
63
77
  </pre>
64
78
 
65
79
  - After running (new haml, new yaml):
66
80
 
67
- Note how some of the strings are replaced, and the ones that shouldn't, aren't. Yup. Beautiful, for 2 and half seconds of work, right?
81
+ running this:
68
82
 
69
- Haml:
83
+ `shai@comp /tmp $ haml-i18n-extractor foo.haml -n -y en.yml`
84
+
85
+ Should give you the below...
86
+
87
+ Note how some of the strings are replaced, and the ones that shouldn't, aren't. Yup. Beautiful, for 2 and half seconds of work, right?
70
88
 
71
89
  <pre>
72
- shai@comp ~/p/project master $ cat app/views/admin/notifications/index.html.i18n-extractor.haml
73
- %h1= t('.consumer_notifications')
74
-
75
- .nav= will_paginate(@consumer_notifications)
76
- %table.themed{cellspacing: 0}
77
- %thead
78
- %tr
79
- %th.first= t('.type')
80
- %th= t('.identifier')
81
- %th= t('.data')
82
- %th= t('.success')
83
- %th= t('.reported_to')
84
- - @consumer_notifications.each do |cn|
85
- %tr
86
- %td.type= cn.notification.type
87
- %td.identifier= cn.notification.identifier
88
- %td.data= cn.notification.data
89
- %td.success= cn.success
90
- %td.reported_to= cn.reported_to
91
- .nav= will_paginate(@consumer_notifications)
90
+
91
+ shai@comp $ cat /tmp/foo.haml
92
+
93
+ = render :partial => "layouts/adminnav", :locals => {:account => nil }
94
+ .row
95
+ .admin.span12
96
+ %h1
97
+ = t('.billing_month')
98
+ = @billing_month.display_name
99
+
100
+ %h3
101
+ = t('.all_invoices_billable')
102
+ %span{:style => (@billable_invoices == @active_invoices) ? "color: #090" : "color: #900"}
103
+ =t('.billable_invoices_out_of_activ', :billable_invoices => (@billable_invoices), :active_invoices => (@active_invoices))
104
+ %h3
105
+ = t('.24_hours_past_end_of_billing_m')
106
+ %span{:style => (@billing_month.past_cutoff) ? "color: #090" : "color: #900"}
107
+ = @billing_month.past_cutoff
108
+
109
+ - if @billing_month.open?
110
+ - if @billing_month.past_cutoff && (@billable_invoices == @active_invoices)
111
+ = form_for @billing_month, :url => close_admin_billing_month_url(@billing_month), :method => "POST" do |f|
112
+ = f.submit "Close This Month (cannot be undone)", :class => 'btn btn-primary'
113
+ - else
114
+ %p
115
+ = t('.billing_month_cannot_be_closed')
116
+ %p
117
+ = t('.closing_the_billing_month_will')
118
+ %p
119
+ = t('.after_closing_you_will_need_to')
120
+ - elsif @billing_month.closing?
121
+ = t('.month_is_currently_closing_rel')
122
+ - elsif @billing_month.closed?
123
+ = t('.month_is_closed')
92
124
  </pre>
93
125
 
94
126
  Yaml:
95
127
 
96
128
  <pre>
97
- shai@comp ~/p/project master $ cat config/locales/en.yml
98
- ---
99
- en:
100
- notifications:
101
- consumer_notifications: Consumer Notifications
102
- type: Type
103
- identifier: Identifier
104
- data: Data
105
- success: Success
106
- reported_to: Reported To
129
+
130
+ shai@comp $ cat /tmp/en.yml
131
+
132
+ ---
133
+ en:
134
+ tmp:
135
+ foo:
136
+ billing_month: Billing Month
137
+ all_invoices_billable: All Invoices Billable?
138
+ billable_invoices_out_of_activ: ! ' "%{billable_invoices} out of %{active_invoices}"'
139
+ 24_hours_past_end_of_billing_m: 24 hours past end of billing month?
140
+ billing_month_cannot_be_closed: Billing Month cannot be closed yet.
141
+ closing_the_billing_month_will: Closing the billing month will mark all the
142
+ invoices as "Posted".
143
+ after_closing_you_will_need_to: After closing you will need to do a payment
144
+ run to charge all the affected customers for the amounts due in posted invoices.
145
+ month_is_currently_closing_rel: Month is currently closing (reload to check
146
+ if it's done)
147
+ month_is_closed: Month is closed
107
148
  </pre>
108
149
 
109
150
 
@@ -3,20 +3,38 @@ module Haml
3
3
  class Extractor
4
4
  class ExceptionFinder
5
5
 
6
- def initialize(text)
7
- @text = text
8
- end
9
-
10
6
  LINK_TO_REGEX_DOUBLE_Q = /link_to\s*\(?\s*["](.*?)["]\s*,\s*(.*)\)?/
11
7
  LINK_TO_REGEX_SINGLE_Q = /link_to\s*\(?\s*['](.*?)[']\s*,\s*(.*)\)?/
12
8
  LINK_TO_BLOCK_FORM_SINGLE_Q = /link_to\s*\(?['](.*?)[']\)?.*\sdo\s*$/
13
9
  LINK_TO_BLOCK_FORM_DOUBLE_Q = /link_to\s*\(?["](.*?)["]\)?.*\sdo\s*$/
14
10
  LINK_TO_NO_QUOTES = /link_to\s*\(?([^'"]*?)\)?.*/
15
11
 
12
+ FORM_SUBMIT_BUTTON_SINGLE_Q = /[a-z]\.submit\s?['](.*?)['].*$/
13
+ FORM_SUBMIT_BUTTON_DOUBLE_Q = /[a-z]\.submit\s?["](.*?)["].*$/
14
+
16
15
  # this class simply returns text except for anything that matches these regexes.
17
16
  # returns first match.
18
17
  EXCEPTION_MATCHES = [ LINK_TO_BLOCK_FORM_DOUBLE_Q, LINK_TO_BLOCK_FORM_SINGLE_Q,
19
- LINK_TO_REGEX_DOUBLE_Q, LINK_TO_REGEX_SINGLE_Q , LINK_TO_NO_QUOTES ]
18
+ LINK_TO_REGEX_DOUBLE_Q, LINK_TO_REGEX_SINGLE_Q , LINK_TO_NO_QUOTES,
19
+ FORM_SUBMIT_BUTTON_SINGLE_Q, FORM_SUBMIT_BUTTON_DOUBLE_Q]
20
+
21
+
22
+ def initialize(text)
23
+ @text = text
24
+ end
25
+
26
+ def self.could_match_script?(txt)
27
+ # want to match:
28
+ # = 'foo'
29
+ # = "foo"
30
+ # = link_to 'bla'
31
+ #
32
+ # but not match:
33
+ # = ruby_var = 2
34
+ scanner = StringScanner.new(txt)
35
+ scanner.scan(/\s+/)
36
+ scanner.scan(/['"]/) || EXCEPTION_MATCHES.any? {|regex| txt.match(regex) }
37
+ end
20
38
 
21
39
  def find
22
40
  ret = @text
@@ -55,7 +55,7 @@ module Haml
55
55
 
56
56
  def script(line)
57
57
  txt = line[:value][:text]
58
- if could_match_script?(txt)
58
+ if ExceptionFinder.could_match_script?(txt)
59
59
  FinderResult.new(:script, ExceptionFinder.new(txt).find)
60
60
  else
61
61
  FinderResult.new(:script, "")
@@ -49,18 +49,6 @@ module Haml
49
49
  txt.match(/link_to/) || txt.match(/^\s*['"]/) # %element= 'foo'
50
50
  end
51
51
 
52
- def could_match_script?(txt)
53
- # want to match:
54
- # = 'foo'
55
- # = "foo"
56
- # = link_to 'bla'
57
- #
58
- # but not match:
59
- # = ruby_var = 2
60
- scanner = StringScanner.new(txt)
61
- scanner.scan(/\s+/)
62
- scanner.scan(/['"]/) || scanner.scan(/link_to/)
63
- end
64
52
  end
65
53
 
66
54
  module Highline
@@ -1,7 +1,7 @@
1
1
  module Haml
2
2
  module I18n
3
3
  class Extractor
4
- VERSION = "0.5.8"
4
+ VERSION = "0.5.9"
5
5
  end
6
6
  end
7
7
  end
@@ -19,7 +19,8 @@ module Haml
19
19
  %{link_to("TEXT"), role: 'button', data: {toggle: 'dropdown'} do} => "TEXT",
20
20
  %{link_to "TEXT", role: 'button', data: {toggle: 'dropdown'} do} => "TEXT",
21
21
  %{link_to pending_account_invoices_path(account) do} => "",
22
- %{link_to(pending_account_invoices_path(account),"http://random")} => ""
22
+ %{link_to(pending_account_invoices_path(account),"http://random")} => "",
23
+ %{f.submit "Close This Month (cannot be undone)", :class => 'btn btn-primary'} => "Close This Month (cannot be undone)"
23
24
  }
24
25
 
25
26
  def test_it_finds_text_pretty_simply
@@ -17,7 +17,7 @@
17
17
  - if @billing_month.open?
18
18
  - if @billing_month.past_cutoff && (@billable_invoices == @active_invoices)
19
19
  = form_for @billing_month, :url => close_admin_billing_month_url(@billing_month), :method => "POST" do |f|
20
- = f.submit "Close This Month (cannot be undone)", :class => 'btn btn-primary'
20
+ = f.submit t('.close_this_month_cannot_be_und'), :class => 'btn btn-primary'
21
21
  - else
22
22
  %p
23
23
  = t('.billing_month_cannot_be_closed')
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml-i18n-extractor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 8
10
- version: 0.5.8
9
+ - 9
10
+ version: 0.5.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Shai Rosenfeld
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-09-15 00:00:00 Z
18
+ date: 2013-09-30 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: tilt