stationed 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +136 -0
  4. data/Rakefile +27 -0
  5. data/app/helpers/crud_link_helper.rb +22 -0
  6. data/app/helpers/page_title_helper.rb +107 -0
  7. data/lib/generators/stationed/templates_generator.rb +24 -0
  8. data/lib/stationed/app_builder.rb +13 -0
  9. data/lib/stationed/crud_tag.rb +70 -0
  10. data/lib/stationed/engine.rb +8 -0
  11. data/lib/stationed/generators/app_generator.rb +52 -0
  12. data/lib/stationed/generators/plugins/capybara.rb +12 -0
  13. data/lib/stationed/generators/plugins/capybara_webkit.rb +14 -0
  14. data/lib/stationed/generators/plugins/database_cleaner.rb +13 -0
  15. data/lib/stationed/generators/plugins/devise.rb +43 -0
  16. data/lib/stationed/generators/plugins/draper.rb +14 -0
  17. data/lib/stationed/generators/plugins/factory_girl.rb +14 -0
  18. data/lib/stationed/generators/plugins/flashes.rb +12 -0
  19. data/lib/stationed/generators/plugins/foreman.rb +15 -0
  20. data/lib/stationed/generators/plugins/generators.rb +12 -0
  21. data/lib/stationed/generators/plugins/guard.rb +26 -0
  22. data/lib/stationed/generators/plugins/haml.rb +12 -0
  23. data/lib/stationed/generators/plugins/i18n_spec.rb +13 -0
  24. data/lib/stationed/generators/plugins/kaminari.rb +18 -0
  25. data/lib/stationed/generators/plugins/layout.rb +13 -0
  26. data/lib/stationed/generators/plugins/normalize.rb +12 -0
  27. data/lib/stationed/generators/plugins/pry.rb +19 -0
  28. data/lib/stationed/generators/plugins/pundit.rb +20 -0
  29. data/lib/stationed/generators/plugins/rack_deflater.rb +17 -0
  30. data/lib/stationed/generators/plugins/responders.rb +28 -0
  31. data/lib/stationed/generators/plugins/rspec.rb +21 -0
  32. data/lib/stationed/generators/plugins/rubocop.rb +14 -0
  33. data/lib/stationed/generators/plugins/simple_form.rb +32 -0
  34. data/lib/stationed/generators/plugins/simple_form_inputs.rb +13 -0
  35. data/lib/stationed/generators/plugins/spring.rb +13 -0
  36. data/lib/stationed/generators/plugins/stationed.rb +12 -0
  37. data/lib/stationed/generators/plugins/strong_parameters.rb +18 -0
  38. data/lib/stationed/generators/plugins/styles.rb +24 -0
  39. data/lib/stationed/generators/plugins/turbolinks.rb +13 -0
  40. data/lib/stationed/generators/plugins/webmock.rb +13 -0
  41. data/lib/stationed/generators/plugins/wiki.rb +20 -0
  42. data/lib/stationed/generators/plugins/yard.rb +14 -0
  43. data/lib/stationed/generators/plugins.rb +10 -0
  44. data/lib/stationed/generators/templates/Deployment.md +3 -0
  45. data/lib/stationed/generators/templates/Home.md +8 -0
  46. data/lib/stationed/generators/templates/Procfile +1 -0
  47. data/lib/stationed/generators/templates/README.md.erb +42 -0
  48. data/lib/stationed/generators/templates/Services.md +3 -0
  49. data/lib/stationed/generators/templates/Setup.md +58 -0
  50. data/lib/stationed/generators/templates/Testing.md +3 -0
  51. data/lib/stationed/generators/templates/application.html.haml +11 -0
  52. data/lib/stationed/generators/templates/application.scss +6 -0
  53. data/lib/stationed/generators/templates/application_decorator.rb +23 -0
  54. data/lib/stationed/generators/templates/application_responder.rb +6 -0
  55. data/lib/stationed/generators/templates/authorization.rb +11 -0
  56. data/lib/stationed/generators/templates/capybara_webkit.rb +1 -0
  57. data/lib/stationed/generators/templates/database_cleaner.rb +19 -0
  58. data/lib/stationed/generators/templates/devise.rb +3 -0
  59. data/lib/stationed/generators/templates/env.erb +3 -0
  60. data/lib/stationed/generators/templates/factories_spec.rb +10 -0
  61. data/lib/stationed/generators/templates/factory_girl.rb +3 -0
  62. data/lib/stationed/generators/templates/flashes.html.haml +5 -0
  63. data/lib/stationed/generators/templates/generators.rb +11 -0
  64. data/lib/stationed/generators/templates/gollum.rake +5 -0
  65. data/lib/stationed/generators/templates/gollum.rb +5 -0
  66. data/lib/stationed/generators/templates/i18n_spec.rb +10 -0
  67. data/lib/stationed/generators/templates/layout.scss +3 -0
  68. data/lib/stationed/generators/templates/normalize.css +425 -0
  69. data/lib/stationed/generators/templates/paginating_decorator.rb +7 -0
  70. data/lib/stationed/generators/templates/pundit.rb +1 -0
  71. data/lib/stationed/generators/templates/rubocop.rake +5 -0
  72. data/lib/stationed/generators/templates/rubocop.yml +38 -0
  73. data/lib/stationed/generators/templates/select2_input.rb +14 -0
  74. data/lib/stationed/generators/templates/simple_form.rb +65 -0
  75. data/lib/stationed/generators/templates/simplecov +6 -0
  76. data/lib/stationed/generators/templates/spec_helper.rb +27 -0
  77. data/lib/stationed/generators/templates/spring.rb +1 -0
  78. data/lib/stationed/generators/templates/static_input.rb +11 -0
  79. data/lib/stationed/generators/templates/webmock.rb +1 -0
  80. data/lib/stationed/generators/templates/yardopts +7 -0
  81. data/lib/stationed/version.rb +3 -0
  82. data/lib/stationed.rb +4 -0
  83. data/lib/tasks/stationed_tasks.rake +4 -0
  84. data/lib/templates/haml/scaffold/_form.html.haml +11 -0
  85. data/lib/templates/haml/scaffold/edit.html.haml +2 -0
  86. data/lib/templates/haml/scaffold/index.html.haml +24 -0
  87. data/lib/templates/haml/scaffold/new.html.haml +2 -0
  88. data/lib/templates/haml/scaffold/show.html.haml +9 -0
  89. data/lib/templates/rails/scaffold_controller/controller.rb +64 -0
  90. data/lib/templates/rspec/integration/request_spec.rb +10 -0
  91. data/lib/templates/rspec/model/model_spec.rb +6 -0
  92. data/lib/templates/rspec/scaffold/controller_spec.rb +224 -0
  93. data/lib/templates/rspec/scaffold/edit_spec.rb +20 -0
  94. data/lib/templates/rspec/scaffold/index_spec.rb +20 -0
  95. data/lib/templates/rspec/scaffold/new_spec.rb +20 -0
  96. data/lib/templates/rspec/scaffold/routing_spec.rb +17 -0
  97. data/lib/templates/rspec/scaffold/show_spec.rb +14 -0
  98. data/spec/dummy/README.rdoc +28 -0
  99. data/spec/dummy/Rakefile +6 -0
  100. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  101. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  102. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  103. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  104. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  105. data/spec/dummy/bin/bundle +3 -0
  106. data/spec/dummy/bin/rails +4 -0
  107. data/spec/dummy/bin/rake +4 -0
  108. data/spec/dummy/config/application.rb +23 -0
  109. data/spec/dummy/config/boot.rb +5 -0
  110. data/spec/dummy/config/database.yml +25 -0
  111. data/spec/dummy/config/environment.rb +5 -0
  112. data/spec/dummy/config/environments/development.rb +29 -0
  113. data/spec/dummy/config/environments/production.rb +80 -0
  114. data/spec/dummy/config/environments/test.rb +36 -0
  115. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  116. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  117. data/spec/dummy/config/initializers/inflections.rb +16 -0
  118. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  119. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  120. data/spec/dummy/config/initializers/session_store.rb +3 -0
  121. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  122. data/spec/dummy/config/locales/en.yml +23 -0
  123. data/spec/dummy/config/routes.rb +56 -0
  124. data/spec/dummy/config.ru +4 -0
  125. data/spec/dummy/db/test.sqlite3 +0 -0
  126. data/spec/dummy/log/development.log +0 -0
  127. data/spec/dummy/log/test.log +1418 -0
  128. data/spec/dummy/public/404.html +58 -0
  129. data/spec/dummy/public/422.html +58 -0
  130. data/spec/dummy/public/500.html +57 -0
  131. data/spec/dummy/public/favicon.ico +0 -0
  132. data/spec/helpers/crud_link_helper_spec.rb +88 -0
  133. data/spec/helpers/page_title_helper_spec.rb +83 -0
  134. data/spec/spec_helper.rb +14 -0
  135. metadata +261 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 38bb78f102e4d35a45d2226d922a0f2c183aa54b
4
+ data.tar.gz: 312a9980d2168f891695ff3897863a7e69b49a44
5
+ SHA512:
6
+ metadata.gz: ee86970abab0e607e449ed93c2104579e1bd903769f53245e0b41c38b856c00b1deec5c663e99cd4fb38e715f04f35071a7e1f281b95b37a0bb8eb9d89f16d4e
7
+ data.tar.gz: d909f871bcbbffb800249f7924ad69ea19921b1ce279c99d931b73b03f162100d51fc4a646b1f2d8e57d65da98bd010e2f0207aa54896f77302a3b61607502cc
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,136 @@
1
+ # Stationed
2
+
3
+ ## Introduction
4
+
5
+ Stationed is an extensive Rails application generator, providing you with a
6
+ starter app full standard goodies such as testing, authentication,
7
+ authorization, decorators, tasks and styles. But as an engine it also provides
8
+ you with customized scaffold generators including proper tests. Finally, it
9
+ provides some basic view helpers that every project tends to need. All in all,
10
+ stationed is pretty sweet.
11
+
12
+ ## Installation
13
+
14
+ In order to use Stationed to generate applications, install the gem:
15
+
16
+ % gem install stationed
17
+
18
+ To use it as an engine in your Rails application, include it in your Gemfile:
19
+
20
+ gem 'stationed'
21
+
22
+ Run `bundle install` and you're all set.
23
+
24
+ ## Application generator
25
+
26
+ The application generator is invoked using the `stationed` command:
27
+
28
+ % stationed my_app
29
+
30
+ This will generate a default Rails application with the following additions:
31
+
32
+ * **Rubocop** for automated style guide testing.
33
+ * **Pry** for debugging.
34
+ * **Guard** for auto-running tests.
35
+ * **Rspec** with Simplecov for testing.
36
+ * **FactoryGirl** for object factories.
37
+ * **DatabaseCleaner** as transaction replacement.
38
+ * **Capybara** for feature testing.
39
+ * **CapybaraWebkit** for headless browser testing.
40
+ * **Pundit** for authorization.
41
+ * **Yard** for API documentation.
42
+ * **Foreman** for process management.
43
+ * **Bourbon, Neat and Bitters and normalize.css** for styling.
44
+ * **Draper** for decorators.
45
+ * **Gollum** for a built-in development wiki.
46
+ * **Devise** for authentication.
47
+ * **Turbolinks** removed.
48
+ * **Kaminari** for pagination.
49
+ * **SimpleForm** for awesome form markup.
50
+ * **Haml** for pretty view templates.
51
+ * **Webmock** to disallow external HTTP requests in tests.
52
+ * **I18nSpec** for automated validation of locale files.
53
+ * **Responders** for DRY controllers.
54
+
55
+ ...and some other minor configurations and goodies.
56
+
57
+ All these additions are stand-alone "plugins" for the base application
58
+ generator, so it is easy to adapt them or add others. Have a look at
59
+ `lib/stationed/generators/plugins` to see all plugins.
60
+
61
+ ## Helpers
62
+
63
+ ### Page title
64
+
65
+ The page title helper allows you to set a page title based on a string,
66
+ translation key or by a resource. You can easily output it on your page and in
67
+ your layout.
68
+
69
+ * When given no argument, this will return the currently set page title or
70
+ the site-wide default.
71
+ * When given a string argument, that will be used in the formatted page
72
+ title (for example with a site-wide suffix).
73
+ * When given an ActiveModel-compliant object, its singular and plural human
74
+ names will be interpolated into the model-based title template, along
75
+ with the record's ID.
76
+
77
+ You can provide templates for page titles using `I18n` in three broad
78
+ categories: the `model`, `formatted` and `standard` keys. These will be used
79
+ when you set a page title via a model, string or nothing at all, respectively.
80
+
81
+ You can specify these translation keys on a global default level, per controller
82
+ or per controller action. The more specific key will take precedence.
83
+
84
+ ### CRUD link helpers
85
+
86
+ A collection of helper methods to generate links to CRUD operations with labels
87
+ and URLs generated by resources.
88
+
89
+ For example:
90
+
91
+ link_to_new(Post) # => <a href="/posts/new">New Post</a>
92
+ link_to_edit(@product) # => <a href="/products/1/edit">Edit Product 1</a>
93
+
94
+ You can use I18n to fully customize the labels on these links. There are helper
95
+ methods for `new`, `edit`, `show`, `destroy` and `index`, in the variants
96
+ `link_to`, `button_to` and `button_link_to` (for links with a `button` class
97
+ name).
98
+
99
+ ### Templates
100
+
101
+ Stationed includes customized scaffold templates for Haml, Rspec and
102
+ controllers. These work out of the box, but you can use a generator to install
103
+ the templates into your application for easy customization:
104
+
105
+ rails generate stationed:templates
106
+
107
+ ## Other
108
+
109
+ ### Note on Patches/Pull Requests
110
+
111
+ 1. Fork the project.
112
+ 2. Make your feature addition or bug fix.
113
+ 3. Add tests for it. This is important so I don't break it in a future version
114
+ unintentionally.
115
+ 4. Commit, do not mess with rakefile, version, or history. (if you want to have
116
+ your own version, that is fine but bump version in a commit by itself I can
117
+ ignore when I pull)
118
+ 5. Send me a pull request. Bonus points for topic branches.
119
+
120
+ ### Issues
121
+
122
+ Please report any issues, defects or suggestions in the [Github issue
123
+ tracker](https://github.com/avdgaag/stationed/issues).
124
+
125
+ ### What has changed?
126
+
127
+ See the [HISTORY](https://github.com/avdgaag/stationed/blob/master/HISTORY.md) file for a detailed changelog.
128
+
129
+ ### Credits
130
+
131
+ Created by: Arjan van der Gaag
132
+ URL: [http://arjanvandergaag.nl](http://arjanvandergaag.nl)
133
+ Project homepage:
134
+ [http://avdgaag.github.com/rpub](http://avdgaag.github.com/stationed)
135
+ Date: april 2014
136
+ License: [MIT-license](https://github.com/avdgaag/stationed/LICENSE) (same as Ruby)
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Stationed'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rspec/core'
23
+ require 'rspec/core/rake_task'
24
+
25
+ desc 'Run all specs in spec directory (excluding plugin specs)'
26
+ RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
27
+ task default: :spec
@@ -0,0 +1,22 @@
1
+ require 'stationed/crud_tag'
2
+
3
+ # Provides links to CRUD-style operations for resources.
4
+ #
5
+ # @see CrudTag
6
+ module CrudLinkHelper
7
+ %i(new edit show index destroy).each do |action|
8
+ define_method :"link_to_#{action}" do |*args|
9
+ Stationed::CrudTag.new(self, :link_to, *args).send action
10
+ end
11
+
12
+ define_method :"button_to_#{action}" do |*args|
13
+ Stationed::CrudTag.new(self, :button_to, *args).send action
14
+ end
15
+
16
+ define_method :"button_link_to_#{action}" do |*args|
17
+ options = args.extract_options!
18
+ options.reverse_merge! class: 'button'
19
+ Stationed::CrudTag.new(self, :link_to, *args, options).send action
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,107 @@
1
+ module PageTitleHelper
2
+ # Sets or retrieves the current page title.
3
+ #
4
+ # * When given no argument, this will return the currently set page title or
5
+ # the site-wide default.
6
+ # * When given a string argument, that will be used in the formatted page
7
+ # title (for example with a site-wide suffix).
8
+ # * When given an ActiveModel-compliant object, its singular and plural human
9
+ # names will be interpolated into the model-based title template, along
10
+ # with the record's ID.
11
+ #
12
+ # You can provide templates for page titles using `I18n` in three broad
13
+ # categories: the `model`, `formatted` and `standard` keys. These will be
14
+ # used when you set a page title via a model, string or nothing at all,
15
+ # respectively.
16
+ #
17
+ # You can specify these translation keys on a global default level, per
18
+ # controller or per controller action. The more specific key will take
19
+ # precedence.
20
+ #
21
+ # @example Set the page title to a string
22
+ # page_title 'Welcome'
23
+ # @example Set the page title based on a model name
24
+ # page_title Post.find(1)
25
+ # # example translation key: 'Editing %{singular} %{id}'
26
+ # @example Show the page title
27
+ # <title><%= title %></title>
28
+ #
29
+ # @param [String, #model_name] String or ActiveModel-compliant object
30
+ # @return [String] page title component or formatted page title
31
+ def page_title(new_title = nil)
32
+ if new_title
33
+ title_from_string_or_record_or_class(new_title).tap do |str|
34
+ content_for :page_title, str
35
+ end
36
+ elsif content_for? :page_title
37
+ formatted_title
38
+ else
39
+ standard_title
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def standard_title
46
+ I18n.translate(
47
+ standard_defaults.first,
48
+ default: standard_defaults.drop(1)
49
+ )
50
+ end
51
+
52
+ def formatted_title
53
+ I18n.translate(
54
+ formatted_defaults.first,
55
+ title: content_for(:page_title),
56
+ default: formatted_defaults.drop(1)
57
+ )
58
+ end
59
+
60
+ def title_for_class(klass, options = {})
61
+ options.reverse_merge!(
62
+ default: model_defaults.drop(1),
63
+ singular: klass.model_name.human,
64
+ plural: klass.model_name.human.pluralize
65
+ )
66
+ I18n.translate model_defaults.first, options
67
+ end
68
+
69
+ def title_from_string_or_record_or_class(object)
70
+ if object.respond_to?(:model_name)
71
+ title_for_class(object)
72
+ elsif object.class.respond_to?(:model_name)
73
+ title_for_class(object.class, id: object.to_param)
74
+ else
75
+ object
76
+ end
77
+ end
78
+
79
+ def formatted_defaults
80
+ [
81
+ :"page_title.#{controller_name}.#{action_name}.formatted",
82
+ :"page_title.#{controller_name}.formatted",
83
+ :'page_title.default.formatted',
84
+ :'page_title.default.standard',
85
+ ::Rails.application.class.parent_name
86
+ ]
87
+ end
88
+
89
+ def standard_defaults
90
+ [
91
+ :"page_title.#{controller_name}.#{action_name}.standard",
92
+ :"page_title.#{controller_name}.standard",
93
+ :'page_title.default.standard',
94
+ ::Rails.application.class.parent_name
95
+ ]
96
+ end
97
+
98
+ def model_defaults
99
+ [
100
+ :"page_title.#{controller_name}.#{action_name}.model",
101
+ :"page_title.#{controller_name}.model",
102
+ :'page_title.default.model',
103
+ :'page_title.default.standard',
104
+ ::Rails.application.class.parent_name
105
+ ]
106
+ end
107
+ end
@@ -0,0 +1,24 @@
1
+ module Stationed
2
+ module Generators
3
+ class TemplatesGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../../../templates', __FILE__)
5
+
6
+ def self.banner
7
+ <<-BANNER.chomp
8
+ rails generate stationed:templates
9
+
10
+ Copies all generator templates from the Stationed gem into your project
11
+ directory for easy customisation.
12
+ BANNER
13
+ end
14
+
15
+ def copy_files
16
+ root = Pathname(self.class.source_root)
17
+ Pathname.glob(root.join('**', '*.{haml,rb}')).each do |path|
18
+ relpath = path.relative_path_from(root)
19
+ copy_file relpath, Pathname('lib/templates').join(relpath)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ module Stationed
2
+ class AppBuilder < Rails::AppBuilder
3
+ def readme
4
+ template 'README.md.erb', 'README.md'
5
+ end
6
+
7
+ def database_yml
8
+ super
9
+ append_to_file '.gitignore', "config/database.yml\n"
10
+ template "config/databases/#{options[:database]}.yml", "config/database.yml.example"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,70 @@
1
+ module Stationed
2
+ # Base class for CRUD-style tags
3
+ class CrudTag
4
+ attr_reader :context, :method, :resource, :model
5
+
6
+ def initialize(context, method, resource, options = {})
7
+ @context = context
8
+ @method = method
9
+ @resource = resource
10
+ @model = Array(resource).last
11
+ @options = options
12
+ end
13
+
14
+ def index
15
+ context.send method, label(:index), model, options
16
+ end
17
+
18
+ def new
19
+ *nested_parts, _ = Array(resource)
20
+ context.send method, label(:new), [:new, *nested_parts, model_name.singular], options
21
+ end
22
+
23
+ def show
24
+ context.send method, label(:show), [*resource], options
25
+ end
26
+
27
+ def edit
28
+ context.send method, label(:edit), [:edit, *resource], options
29
+ end
30
+
31
+ def destroy
32
+ context.send method, label(:destroy), [*resource], options.merge(data: { method: :delete })
33
+ end
34
+
35
+ private
36
+
37
+ def options
38
+ default_options.merge(@options)
39
+ end
40
+
41
+ def model_name
42
+ @model_name ||=
43
+ if @model.respond_to?(:model_name)
44
+ @model.model_name
45
+ elsif @model.class.respond_to?(:model_name)
46
+ @model.class.model_name
47
+ else
48
+ fail ArgumentError,
49
+ 'Pass in an ActiveModel-compliant record or class'
50
+ end
51
+ end
52
+
53
+ def default_options
54
+ {}
55
+ end
56
+
57
+ def label(action)
58
+ context.translate(
59
+ :"helpers.buttons.#{model_name.i18n_key}.#{action}",
60
+ default: [
61
+ :"helpers.buttons.defaults.#{action}",
62
+ "#{action.capitalize} %{model}"
63
+ ],
64
+ model: model_name.human,
65
+ plural: model_name.human.pluralize,
66
+ id: model.to_param
67
+ )
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,8 @@
1
+ module Stationed
2
+ class Engine < ::Rails::Engine
3
+ config.app_generators do |g|
4
+ g.templates.unshift File.expand_path('../../templates', __FILE__)
5
+ g.scaffold_controller :scaffold_controller
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,52 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/rails/app/app_generator'
3
+ require 'stationed/app_builder'
4
+ require 'stationed/generators/plugins'
5
+
6
+ module Stationed
7
+ module Generators
8
+ class AppGenerator < Rails::Generators::AppGenerator
9
+ source_root File.expand_path('../templates', __FILE__)
10
+ source_paths << Rails::Generators::AppGenerator.source_root
11
+ source_paths << source_root
12
+
13
+ prepend Plugins::Rubocop
14
+ prepend Plugins::Pry
15
+ prepend Plugins::Guard
16
+ prepend Plugins::Rspec
17
+ prepend Plugins::FactoryGirl
18
+ prepend Plugins::DatabaseCleaner
19
+ prepend Plugins::Capybara
20
+ prepend Plugins::CapybaraWebkit
21
+ prepend Plugins::Pundit
22
+ prepend Plugins::Yard
23
+ prepend Plugins::Foreman
24
+ prepend Plugins::Styles
25
+ prepend Plugins::Draper
26
+ prepend Plugins::Wiki
27
+ prepend Plugins::Generators
28
+ prepend Plugins::Devise
29
+ prepend Plugins::Turbolinks
30
+ prepend Plugins::Kaminari
31
+ prepend Plugins::SimpleForm
32
+ prepend Plugins::Haml
33
+ prepend Plugins::StrongParameters
34
+ prepend Plugins::RackDeflater
35
+ prepend Plugins::Flashes
36
+ prepend Plugins::Webmock
37
+ prepend Plugins::Layout
38
+ prepend Plugins::Normalize
39
+ prepend Plugins::I18nSpec
40
+ prepend Plugins::SimpleFormInputs
41
+ prepend Plugins::Spring
42
+ prepend Plugins::Stationed
43
+ prepend Plugins::Responders
44
+
45
+ protected
46
+
47
+ def get_builder_class
48
+ Stationed::AppBuilder
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+ module Stationed
2
+ module Generators
3
+ module Plugins
4
+ module Capybara
5
+ def finish_template
6
+ gem 'capybara', group: :test
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module Stationed
2
+ module Generators
3
+ module Plugins
4
+ module CapybaraWebkit
5
+ def finish_template
6
+ gem 'capybara-webkit', group: :test
7
+ copy_file 'capybara_webkit.rb', 'spec/support/capybara_webkit.rb'
8
+ super
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,13 @@
1
+ module Stationed
2
+ module Generators
3
+ module Plugins
4
+ module DatabaseCleaner
5
+ def finish_template
6
+ gem 'database_cleaner', group: :test
7
+ copy_file 'database_cleaner.rb', 'spec/support/database_cleaner.rb'
8
+ super
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,43 @@
1
+ module Stationed
2
+ module Generators
3
+ module Plugins
4
+ module Devise
5
+ def finish_template
6
+ gem 'devise'
7
+ copy_file 'devise.rb', 'spec/support/devise.rb'
8
+ route "devise_scope :user do\n root to: 'devise/sessions#new'\n end\n"
9
+ environment nil, env: :test do
10
+ "config.action_mailer.default_url_options = { host: 'example.com' }"
11
+ end
12
+ environment nil, env: :development do
13
+ "config.action_mailer.default_url_options = { host: 'localhost:3000' }"
14
+ end
15
+ super
16
+ end
17
+
18
+ def run_bundle
19
+ super
20
+ generate 'devise:install'
21
+ generate 'devise user'
22
+ application do
23
+ <<-RUBY
24
+ # Let Pundit authorization or custom responders not influence the workings
25
+ # of Devise.
26
+ config.to_prepare do
27
+ [
28
+ Devise::SessionsController,
29
+ Devise::RegistrationsController,
30
+ Devise::PasswordsController
31
+ ].each do |devise_controller_class|
32
+ devise_controller_class.skip_after_action :verify_authorized
33
+ devise_controller_class.skip_after_action :verify_policy_scoped
34
+ devise_controller_class.responder = ActionController::Responder
35
+ end
36
+ end
37
+ RUBY
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,14 @@
1
+ module Stationed
2
+ module Generators
3
+ module Plugins
4
+ module Draper
5
+ def finish_template
6
+ gem 'draper'
7
+ copy_file 'application_decorator.rb', 'app/decorators/application_decorator.rb'
8
+ copy_file 'paginating_decorator.rb', 'app/decorators/paginating_decorator.rb'
9
+ super
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Stationed
2
+ module Generators
3
+ module Plugins
4
+ module FactoryGirl
5
+ def finish_template
6
+ gem 'factory_girl_rails', group: [:development, :test]
7
+ copy_file 'factory_girl.rb', 'spec/support/factory_girl.rb'
8
+ copy_file 'factories_spec.rb', 'spec/models/factories_spec.rb'
9
+ super
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module Stationed
2
+ module Generators
3
+ module Plugins
4
+ module Flashes
5
+ def finish_template
6
+ copy_file 'flashes.html.haml', 'app/views/application/_flashes.html.haml'
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module Stationed
2
+ module Generators
3
+ module Plugins
4
+ module Foreman
5
+ def finish_template
6
+ gem 'foreman'
7
+ gem 'yard', require: false, group: :doc
8
+ copy_file 'Procfile', 'Procfile'
9
+ template 'env.erb', '.env'
10
+ super
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module Stationed
2
+ module Generators
3
+ module Plugins
4
+ module Generators
5
+ def finish_template
6
+ copy_file 'generators.rb', 'config/initializers/generators.rb'
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ module Stationed
2
+ module Generators
3
+ module Plugins
4
+ module Guard
5
+ def finish_template
6
+ gem_group :development do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-livereload'
10
+ gem 'terminal-notifier-guard'
11
+ end
12
+ super
13
+ end
14
+
15
+ def run_bundle
16
+ super
17
+ run 'bundle exec guard init rspec'
18
+ run 'bundle exec guard init livereload'
19
+ gsub_file 'Guardfile',
20
+ /guard :rspec do/,
21
+ "guard :rspec, cmd: 'spring rspec' do"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end