stationed 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddd733df0111d69ab25025b8cd2cd21d46b5df23
4
- data.tar.gz: b1574b28a98ef141d8b7b1354f07848edc6f3c87
3
+ metadata.gz: f8a940b7b782fd708f9dbdb1b3e10d3507fb44d8
4
+ data.tar.gz: 7e1aea4eec20e7d767922eda2ba8f637b59367dc
5
5
  SHA512:
6
- metadata.gz: b658a1b9f224f88cd45eefd99a32e3a1b942d22c5e958b995f08d3840dd1dff4c228172fa2d290251b64b787e50b04de8669258122c447f2b9e959ad13bfa486
7
- data.tar.gz: 40ab1e4c1ca98273577df0f1e0235aa1ccec4df7dac8e1e344d3a64625efd762252fb52d72a81073b2660c6001af17373f5521e38f3697878afeef5e84ec476b
6
+ metadata.gz: 023db417672a5477980cf5b8c1f2049a09d7a4356d4ce086cb6d74eff4064d6e85dd0c0e23819c07440ca44ae5629ad1eec133027ab295eec48c693e33c0234b
7
+ data.tar.gz: 0ef4a07defd85264ff48e1195db0c74a79f46ed166cb1565e75880e31ca141916941f5ee89677bf3d2e5ad5b573b185894f14117045703b0e00a49fa5c92f26d
data/README.md CHANGED
@@ -99,6 +99,27 @@ methods for `new`, `edit`, `show`, `destroy` and `index`, in the variants
99
99
  `link_to`, `button_to` and `button_link_to` (for links with a `button` class
100
100
  name).
101
101
 
102
+ ### Placeholders
103
+
104
+ Display a placeholder message using standardized markup and a message defined
105
+ through I18n.
106
+
107
+ When in a controller PostsController and action index, this will try to look up
108
+ the following placeholder keys:
109
+
110
+ * placeholders.posts.index
111
+ * placeholders.posts.default
112
+ * placeholders.defaults.index
113
+
114
+ You can also provide an argument to set the placeholder message. When given a
115
+ string, it will be used directly as the placeholder message. When given a
116
+ symbol, that key will be looked up in the `placeholders.defaults` namespace
117
+ using I18n.
118
+
119
+ For example:
120
+
121
+ placeholder('Nothing found') # => '<p class="placeholder">Nothing found</p>'
122
+
102
123
  ### Templates
103
124
 
104
125
  Stationed includes customized scaffold templates for Haml, Rspec and
@@ -0,0 +1,45 @@
1
+ # Provides the `placeholder` helper method for showing standard markup
2
+ # for when thing are missing or not present yet.
3
+ module PlaceholderHelper
4
+ # Display a placeholder message using standardized markup and a message
5
+ # defined through I18n.
6
+ #
7
+ # When in a controller PostsController and action index, this will try
8
+ # to look up the following placeholder keys:
9
+ #
10
+ # * placeholders.posts.index
11
+ # * placeholders.posts.default
12
+ # * placeholders.defaults.index
13
+ #
14
+ # You can also provide an argument to set the placeholder message. When given
15
+ # a string, it will be used directly as the placeholder message. When given a
16
+ # symbol, that key will be looked up in the `placeholders.defaults` namespace
17
+ # using I18n.
18
+ #
19
+ # @return [String] e.g. '<p class="placeholder">Nothing to show</p>'
20
+ def placeholder(label = nil, tag: :p)
21
+ content_tag(tag, placeholder_text(label), class: 'placeholder')
22
+ end
23
+
24
+ private
25
+
26
+ def placeholder_text(label)
27
+ case label
28
+ when Symbol
29
+ defaults = [
30
+ :"placeholders.defaults.#{label}",
31
+ :'placeholders.defaults.default'
32
+ ]
33
+ translate(defaults.shift, default: defaults)
34
+ when nil
35
+ defaults = [
36
+ :"placeholders.#{controller_name}.#{action_name}",
37
+ :"placeholders.#{controller_name}.default",
38
+ :"placeholders.defaults.#{action_name}"
39
+ ]
40
+ translate defaults.shift, default: defaults
41
+ else
42
+ label.to_s
43
+ end
44
+ end
45
+ end
@@ -15,10 +15,10 @@ module Stationed
15
15
  copy_file 'devise.rb', 'spec/support/devise.rb' if options[:rspec]
16
16
  route "devise_scope :user do\n root to: 'devise/sessions#new'\n end\n"
17
17
  environment nil, env: :test do
18
- "config.action_mailer.default_url_options = { host: 'example.com' }"
18
+ "# Set default url options for Devise mailers\n config.action_mailer.default_url_options = { host: 'example.com' }\n"
19
19
  end
20
20
  environment nil, env: :development do
21
- "config.action_mailer.default_url_options = { host: 'localhost:3000' }"
21
+ "# Set default url options for Devise mailers\n config.action_mailer.default_url_options = { host: 'localhost:3000' }\n"
22
22
  end
23
23
  super
24
24
  end
@@ -13,6 +13,8 @@ module Stationed
13
13
  return super unless options[:i18n_spec]
14
14
  gem 'i18n-spec', group: :test
15
15
  copy_file 'i18n_spec.rb', 'spec/locales/i18n_spec.rb'
16
+ uncomment_lines 'config/environments/development.rb', /raise_on_missing_translations/
17
+ uncomment_lines 'config/environments/test.rb', /raise_on_missing_translations/
16
18
  super
17
19
  end
18
20
  end
@@ -14,8 +14,8 @@ module Stationed
14
14
  environment nil, env: :development do
15
15
  <<-RUBY
16
16
  # Raise an ActionController::UnpermittedParameters exception when
17
- # a parameter is not explcitly permitted but is passed anyway.
18
- config.action_controller.action_on_unpermitted_parameters = :raise
17
+ # a parameter is not explcitly permitted but is passed anyway.
18
+ config.action_controller.action_on_unpermitted_parameters = :raise
19
19
  RUBY
20
20
  end
21
21
  super
@@ -14,6 +14,7 @@ module Stationed
14
14
  gem 'yard', require: false, group: :doc
15
15
  gem 'kramdown', require: false, group: :doc
16
16
  copy_file 'yardopts', '.yardopts'
17
+ copy_file 'yard.rake', 'lib/tasks/yard.rake'
17
18
  super
18
19
  end
19
20
  end
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'yard'
3
+ namespace :doc do
4
+ YARD::Rake::YardocTask.new
5
+ end
6
+ rescue LoadError
7
+ end
@@ -1,3 +1,3 @@
1
1
  module Stationed
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -1472,3 +1472,109 @@
1472
1472
   (0.0ms) rollback transaction
1473
1473
   (0.0ms) begin transaction
1474
1474
   (0.0ms) rollback transaction
1475
+  (0.3ms) begin transaction
1476
+  (0.1ms) rollback transaction
1477
+  (0.0ms) begin transaction
1478
+  (0.0ms) rollback transaction
1479
+  (0.0ms) begin transaction
1480
+  (0.0ms) rollback transaction
1481
+  (0.0ms) begin transaction
1482
+  (0.0ms) rollback transaction
1483
+  (0.0ms) begin transaction
1484
+  (0.0ms) rollback transaction
1485
+  (0.1ms) begin transaction
1486
+  (0.1ms) rollback transaction
1487
+  (0.0ms) begin transaction
1488
+  (0.0ms) rollback transaction
1489
+  (0.0ms) begin transaction
1490
+  (0.1ms) rollback transaction
1491
+  (0.0ms) begin transaction
1492
+  (0.1ms) rollback transaction
1493
+  (0.0ms) begin transaction
1494
+  (0.0ms) rollback transaction
1495
+  (0.0ms) begin transaction
1496
+  (0.0ms) rollback transaction
1497
+  (0.0ms) begin transaction
1498
+  (0.1ms) rollback transaction
1499
+  (0.0ms) begin transaction
1500
+  (0.1ms) rollback transaction
1501
+  (0.0ms) begin transaction
1502
+  (0.1ms) rollback transaction
1503
+  (0.2ms) begin transaction
1504
+  (0.1ms) rollback transaction
1505
+  (0.2ms) begin transaction
1506
+  (0.1ms) rollback transaction
1507
+  (0.0ms) begin transaction
1508
+  (0.0ms) rollback transaction
1509
+  (0.2ms) begin transaction
1510
+  (0.1ms) rollback transaction
1511
+  (0.1ms) begin transaction
1512
+  (0.1ms) rollback transaction
1513
+  (0.0ms) begin transaction
1514
+  (0.0ms) rollback transaction
1515
+  (0.2ms) begin transaction
1516
+  (0.1ms) rollback transaction
1517
+  (0.0ms) begin transaction
1518
+  (0.0ms) rollback transaction
1519
+  (0.0ms) begin transaction
1520
+  (0.0ms) rollback transaction
1521
+  (0.0ms) begin transaction
1522
+  (0.0ms) rollback transaction
1523
+  (0.2ms) begin transaction
1524
+  (0.1ms) rollback transaction
1525
+  (0.0ms) begin transaction
1526
+  (0.0ms) rollback transaction
1527
+  (0.0ms) begin transaction
1528
+  (0.0ms) rollback transaction
1529
+  (0.0ms) begin transaction
1530
+  (0.0ms) rollback transaction
1531
+  (0.0ms) begin transaction
1532
+  (0.0ms) rollback transaction
1533
+  (0.2ms) begin transaction
1534
+  (0.1ms) rollback transaction
1535
+  (0.0ms) begin transaction
1536
+  (0.0ms) rollback transaction
1537
+  (0.1ms) begin transaction
1538
+  (0.0ms) rollback transaction
1539
+  (0.0ms) begin transaction
1540
+  (0.0ms) rollback transaction
1541
+  (0.0ms) begin transaction
1542
+  (0.0ms) rollback transaction
1543
+  (0.0ms) begin transaction
1544
+  (0.0ms) rollback transaction
1545
+  (0.3ms) begin transaction
1546
+  (0.1ms) rollback transaction
1547
+  (0.0ms) begin transaction
1548
+  (0.0ms) rollback transaction
1549
+  (0.0ms) begin transaction
1550
+  (0.0ms) rollback transaction
1551
+  (0.1ms) begin transaction
1552
+  (0.0ms) rollback transaction
1553
+  (0.0ms) begin transaction
1554
+  (0.0ms) rollback transaction
1555
+  (0.0ms) begin transaction
1556
+  (0.0ms) rollback transaction
1557
+  (0.2ms) begin transaction
1558
+  (0.1ms) rollback transaction
1559
+  (0.0ms) begin transaction
1560
+  (0.1ms) rollback transaction
1561
+  (0.0ms) begin transaction
1562
+  (0.0ms) rollback transaction
1563
+  (0.1ms) begin transaction
1564
+  (0.0ms) rollback transaction
1565
+  (0.0ms) begin transaction
1566
+  (0.0ms) rollback transaction
1567
+  (0.0ms) begin transaction
1568
+  (0.0ms) rollback transaction
1569
+  (0.2ms) begin transaction
1570
+  (0.1ms) rollback transaction
1571
+  (0.0ms) begin transaction
1572
+  (0.0ms) rollback transaction
1573
+  (0.0ms) begin transaction
1574
+  (0.0ms) rollback transaction
1575
+  (0.0ms) begin transaction
1576
+  (0.0ms) rollback transaction
1577
+  (0.0ms) begin transaction
1578
+  (0.0ms) rollback transaction
1579
+  (0.0ms) begin transaction
1580
+  (0.0ms) rollback transaction
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe PlaceholderHelper do
4
+ before do
5
+ allow(helper).to receive(:controller_name).and_return('products')
6
+ allow(helper).to receive(:action_name).and_return('index')
7
+ end
8
+
9
+ it 'fetches default key by controller action first' do
10
+ I18n.backend.store_translations :en, placeholders: { products: { index: 'Nothing found' } }
11
+ expect(helper.placeholder).to eql('<p class="placeholder">Nothing found</p>')
12
+ end
13
+
14
+ it 'fetches default key by controller second' do
15
+ I18n.backend.store_translations :en, placeholders: { products: { default: 'Nothing found' } }
16
+ expect(helper.placeholder).to eql('<p class="placeholder">Nothing found</p>')
17
+ end
18
+
19
+ it 'fetches default key by action third' do
20
+ I18n.backend.store_translations :en, placeholders: { defaults: { index: 'Nothing found' } }
21
+ expect(helper.placeholder).to eql('<p class="placeholder">Nothing found</p>')
22
+ end
23
+
24
+ it 'fetches custom default key' do
25
+ I18n.backend.store_translations :en, placeholders: { defaults: { foo: 'Nothing found' } }
26
+ expect(helper.placeholder(:foo)).to eql('<p class="placeholder">Nothing found</p>')
27
+ end
28
+
29
+ it 'uses plain string' do
30
+ expect(helper.placeholder('Nothing found')).to eql('<p class="placeholder">Nothing found</p>')
31
+ end
32
+
33
+ it 'allows using a custom tag' do
34
+ expect(helper.placeholder('Nothing found', tag: :span)).to eql('<span class="placeholder">Nothing found</span>')
35
+ end
36
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stationed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arjan van der Gaag
@@ -70,6 +70,7 @@ files:
70
70
  - Rakefile
71
71
  - app/helpers/crud_link_helper.rb
72
72
  - app/helpers/page_title_helper.rb
73
+ - app/helpers/placeholder_helper.rb
73
74
  - lib/generators/stationed/templates_generator.rb
74
75
  - lib/stationed.rb
75
76
  - lib/stationed/app_builder.rb
@@ -143,6 +144,7 @@ files:
143
144
  - lib/stationed/generators/templates/spring.rb
144
145
  - lib/stationed/generators/templates/static_input.rb
145
146
  - lib/stationed/generators/templates/webmock.rb
147
+ - lib/stationed/generators/templates/yard.rake
146
148
  - lib/stationed/generators/templates/yardopts
147
149
  - lib/stationed/version.rb
148
150
  - lib/tasks/stationed_tasks.rake
@@ -196,6 +198,7 @@ files:
196
198
  - spec/dummy/public/favicon.ico
197
199
  - spec/helpers/crud_link_helper_spec.rb
198
200
  - spec/helpers/page_title_helper_spec.rb
201
+ - spec/helpers/placeholder_helper_spec.rb
199
202
  - spec/spec_helper.rb
200
203
  homepage: http://avdgaag.github.io/stationed
201
204
  licenses: []
@@ -257,4 +260,5 @@ test_files:
257
260
  - spec/dummy/README.rdoc
258
261
  - spec/helpers/crud_link_helper_spec.rb
259
262
  - spec/helpers/page_title_helper_spec.rb
263
+ - spec/helpers/placeholder_helper_spec.rb
260
264
  - spec/spec_helper.rb