silmarails 0.1.1

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.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +188 -0
  4. data/Rakefile +57 -0
  5. data/app/assets/javascripts/magic_view.coffee +4 -0
  6. data/app/assets/javascripts/magic_view/init.coffee +25 -0
  7. data/app/assets/stylesheets/scaffold.css +56 -0
  8. data/config/routes.rb +2 -0
  9. data/lib/generators/silmarails/install/USAGE +8 -0
  10. data/lib/generators/silmarails/install/files/spec/support/silmarails.rb +33 -0
  11. data/lib/generators/silmarails/install/files/templates/active_record/model/model.rb +22 -0
  12. data/lib/generators/silmarails/install/files/templates/coffee/assets/javascript.coffee +11 -0
  13. data/lib/generators/silmarails/install/files/templates/erb/scaffold/_form.html.erb +23 -0
  14. data/lib/generators/silmarails/install/files/templates/erb/scaffold/edit.html.erb +11 -0
  15. data/lib/generators/silmarails/install/files/templates/erb/scaffold/index.html.erb +44 -0
  16. data/lib/generators/silmarails/install/files/templates/erb/scaffold/new.html.erb +9 -0
  17. data/lib/generators/silmarails/install/files/templates/erb/scaffold/show.html.erb +25 -0
  18. data/lib/generators/silmarails/install/files/templates/rails/responders_controller/controller.rb +59 -0
  19. data/lib/generators/silmarails/install/files/templates/rspec/scaffold/controller_spec.rb +163 -0
  20. data/lib/generators/silmarails/install/files/templates/rspec/scaffold/edit_spec.rb +19 -0
  21. data/lib/generators/silmarails/install/files/templates/rspec/scaffold/index_spec.rb +17 -0
  22. data/lib/generators/silmarails/install/files/templates/rspec/scaffold/new_spec.rb +19 -0
  23. data/lib/generators/silmarails/install/files/templates/rspec/scaffold/routing_spec.rb +45 -0
  24. data/lib/generators/silmarails/install/files/templates/rspec/scaffold/show_spec.rb +15 -0
  25. data/lib/generators/silmarails/install/install_generator.rb +22 -0
  26. data/lib/silmarails.rb +6 -0
  27. data/lib/silmarails/auto_include_magic_view.rb +52 -0
  28. data/lib/silmarails/engine.rb +4 -0
  29. data/lib/silmarails/railtie.rb +12 -0
  30. data/lib/silmarails/version.rb +3 -0
  31. data/lib/tasks/silmarails_tasks.rake +4 -0
  32. data/test/dummy/README.rdoc +28 -0
  33. data/test/dummy/Rakefile +6 -0
  34. data/test/dummy/app/assets/javascripts/application.js +13 -0
  35. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  36. data/test/dummy/app/controllers/application_controller.rb +5 -0
  37. data/test/dummy/app/helpers/application_helper.rb +2 -0
  38. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  39. data/test/dummy/bin/bundle +3 -0
  40. data/test/dummy/bin/rails +4 -0
  41. data/test/dummy/bin/rake +4 -0
  42. data/test/dummy/bin/setup +29 -0
  43. data/test/dummy/config.ru +4 -0
  44. data/test/dummy/config/application.rb +26 -0
  45. data/test/dummy/config/boot.rb +5 -0
  46. data/test/dummy/config/database.yml +25 -0
  47. data/test/dummy/config/environment.rb +5 -0
  48. data/test/dummy/config/environments/development.rb +41 -0
  49. data/test/dummy/config/environments/production.rb +79 -0
  50. data/test/dummy/config/environments/test.rb +42 -0
  51. data/test/dummy/config/initializers/assets.rb +11 -0
  52. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  53. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  54. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  55. data/test/dummy/config/initializers/inflections.rb +16 -0
  56. data/test/dummy/config/initializers/mime_types.rb +4 -0
  57. data/test/dummy/config/initializers/session_store.rb +3 -0
  58. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  59. data/test/dummy/config/locales/en.yml +23 -0
  60. data/test/dummy/config/routes.rb +56 -0
  61. data/test/dummy/config/secrets.yml +22 -0
  62. data/test/dummy/lib/templates/rspec/controller/controller_spec.rb +16 -0
  63. data/test/dummy/lib/templates/rspec/controller/view_spec.rb +5 -0
  64. data/test/dummy/lib/templates/rspec/helper/helper_spec.rb +17 -0
  65. data/test/dummy/lib/templates/rspec/integration/request_spec.rb +10 -0
  66. data/test/dummy/lib/templates/rspec/mailer/fixture +3 -0
  67. data/test/dummy/lib/templates/rspec/mailer/mailer_spec.rb +25 -0
  68. data/test/dummy/lib/templates/rspec/mailer/preview.rb +13 -0
  69. data/test/dummy/lib/templates/rspec/model/fixtures.yml +19 -0
  70. data/test/dummy/lib/templates/rspec/model/model_spec.rb +7 -0
  71. data/test/dummy/lib/templates/rspec/observer/observer_spec.rb +7 -0
  72. data/test/dummy/lib/templates/rspec/scaffold/controller_spec.rb +163 -0
  73. data/test/dummy/lib/templates/rspec/scaffold/edit_spec.rb +23 -0
  74. data/test/dummy/lib/templates/rspec/scaffold/index_spec.rb +25 -0
  75. data/test/dummy/lib/templates/rspec/scaffold/new_spec.rb +22 -0
  76. data/test/dummy/lib/templates/rspec/scaffold/routing_spec.rb +45 -0
  77. data/test/dummy/lib/templates/rspec/scaffold/show_spec.rb +21 -0
  78. data/test/dummy/lib/templates/rspec/view/view_spec.rb +5 -0
  79. data/test/dummy/public/404.html +67 -0
  80. data/test/dummy/public/422.html +67 -0
  81. data/test/dummy/public/500.html +66 -0
  82. data/test/dummy/public/favicon.ico +0 -0
  83. data/test/integration/navigation_test.rb +8 -0
  84. data/test/silmarails_test.rb +7 -0
  85. data/test/test_helper.rb +20 -0
  86. metadata +227 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5038a4b76855b99d2b34ffb7a2b6755a6d660737
4
+ data.tar.gz: c024c7cc2899c518f5c14405b270b5393fc92c7a
5
+ SHA512:
6
+ metadata.gz: 8c0ca654399858d4c8ff9f481253df488ac4e6669ca013c10e9be4c2c2e12c006964df526aee595a76e4aff48b4193c8696aa5f6915755eed44a7d921b0bb99e
7
+ data.tar.gz: 0ce5c3df6b92a8d45ea78e93c3238c3cf2fdff88541245ad85e7e12558ca062fce5acf97a0e7fb39aff95372bc29ab0e4827bdfe4f4d2c1f30ca925f3d3b4caa
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Kelvin Stinghen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,188 @@
1
+ # silmarails
2
+
3
+ Silmarails is a warehouse for templates and initial configurations for
4
+ brand new rails project with the minimum needed for a quick development
5
+ environment.
6
+
7
+ ## Pre requisites
8
+
9
+ So, there is no explicit pre requisite to install this gem and use it in your
10
+ rails project. But I actually recommend to be running with `rails ~> 4.2`,
11
+ `ruby ~> 2.2`, `postgres` (any version) aaaaaaand, if you are creating your
12
+ project now, to create it with the following command:
13
+
14
+ ```bash
15
+ rails new my_project -T -d postgresql
16
+ ```
17
+
18
+ That's it!
19
+
20
+ ## Install
21
+
22
+ To intall this project, first, you need to add the following to your Gemfile:
23
+
24
+ ```ruby
25
+ gem 'silmarails'
26
+ gem 'kaminari'
27
+ gem 'responders'
28
+ gem 'simple_form'
29
+
30
+ group :test do
31
+ gem "rspec"
32
+ gem "rspec-rails"
33
+ gem "capybara"
34
+ gem "database_cleaner"
35
+ gem 'factory_girl_rails'
36
+ end
37
+
38
+ source 'https://rails-assets.org' do
39
+ gem 'rails-assets-bootstrap'
40
+ end
41
+ ```
42
+
43
+ Then:
44
+
45
+ ```bash
46
+ bundle install
47
+ ```
48
+
49
+ The other gems are not hard dependencies, but we have some templates defined
50
+ that need them to work correctly, please check their installation guides
51
+ individually. If you are not so interested in reading everyone, here comes a
52
+ list of commands you'll probably need to execute:
53
+
54
+ ```bash
55
+ rails g kaminari:config
56
+ rails g kaminari:views bootstrap3
57
+ rails g responders:install
58
+ rails g simple_form:install --bootstrap
59
+ rails g rspec:install
60
+ ```
61
+
62
+ And finally:
63
+
64
+ ```bash
65
+ rails g silmarails:install
66
+ ```
67
+
68
+ This will copy all the default templates into your rails project, and may have
69
+ conflicts with other gems. If so, just diff them and choose which one you
70
+ prefer.
71
+
72
+ It's important to remember that this needs to be recopied everytime there is a
73
+ update on them.
74
+
75
+ ## How to update
76
+
77
+ Well, that's a long story. Depends of course on how many things are you updating
78
+ at once, but I would recommend update all of them separetedly. So:
79
+
80
+ ```bash
81
+ bundle update silmarails
82
+ ```
83
+
84
+ After that, you'll be able to just:
85
+
86
+
87
+ ```bash
88
+ rails g silmarails:install
89
+ ```
90
+
91
+ This, of course, can have changes dependeding on which is the update and take
92
+ attention to your changes to the templates you've copied. Choose wisely if you
93
+ want or not the new version. :stuck_out_and_tongue:
94
+
95
+ ## Recommended configuration
96
+
97
+ Follows some recommended configuration for your application if you are using
98
+ silmarails:
99
+
100
+ ```
101
+ <app/assets/stylesheets/application.css>
102
+ # add the following lines to ignore the scaffolds file and import the needed
103
+ # bootstrap
104
+ *= stub scaffolds
105
+ *= require bootstrap
106
+
107
+ <app/assets/javascripts/application.js>
108
+ # add the following lines to import the needed bootstrap
109
+ //= require bootstrap
110
+ //= require magic_view
111
+
112
+ # then, at the end of file, add the following line to init the magic_view code
113
+ //= require magic_view/init
114
+
115
+ <config/application.rb>
116
+ # add the following lines to configure the generators properly
117
+ config.generators do |g|
118
+ g.test_framework :rspec,
119
+ fixtures: true,
120
+ model_specs: false,
121
+ helper_specs: false
122
+ g.fixture_replacement :factory_girl
123
+ g.factory_girl dir: "spec/factories"
124
+ end
125
+
126
+ <spec/rails_helper.rb>
127
+ # uncomment the following line to require the needed support files (one of them
128
+ # is copied on the silmarails installations)
129
+ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
130
+
131
+ # then change the value of the following config to false (the raise of the code below
132
+ # is granting this will be always that way and explaining why it's needed, but
133
+ # I'm warning you one more tim: DO THIS AND DON'T REMOVE THAT RAISE!!!!!!)
134
+ config.use_transactional_fixtures = false
135
+
136
+ # and finally add the following lines to configure the database cleaner for your
137
+ # rspec tests (put them inside the
138
+ config.before(:suite) do
139
+ # don't remove this raise for the sake of God!!!
140
+ if config.use_transactional_fixtures?
141
+ raise(<<-MSG)
142
+ Delete line `config.use_transactional_fixtures = true` from rails_helper.rb
143
+ (or set it to false) to prevent uncommitted transactions being used in
144
+ JavaScript-dependent specs.
145
+
146
+ During testing, the app-under-test that the browser driver connects to
147
+ uses a different database connection to the database connection used by
148
+ the spec. The app's database connection would not be able to access
149
+ uncommitted transaction data setup over the spec's database connection.
150
+ MSG
151
+ end
152
+ DatabaseCleaner.clean_with(:truncation)
153
+ end
154
+
155
+ config.before(:each) do
156
+ DatabaseCleaner.strategy = :transaction
157
+ end
158
+
159
+ config.before(:each, type: :feature) do
160
+ # :rack_test driver's Rack app under test shares database connection
161
+ # with the specs, so continue to use transaction strategy for speed.
162
+ driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
163
+
164
+ unless driver_shares_db_connection_with_specs
165
+ # Driver is probably for an external browser with an app
166
+ # under test that does *not* share a database connection with the
167
+ # specs, so use truncation strategy.
168
+ DatabaseCleaner.strategy = :truncation
169
+ end
170
+ end
171
+
172
+ config.before(:each) do
173
+ DatabaseCleaner.start
174
+ end
175
+
176
+ config.append_after(:each) do
177
+ DatabaseCleaner.clean
178
+ end
179
+ ```
180
+
181
+ ## TODO
182
+
183
+ - [ ] Make the install generator to configure the project with the above
184
+ recommended configuration
185
+ - [ ] Create a way to choose which frameworks and helpers to include when
186
+ installing, aaand copy the correct templates and files according on which were
187
+ selected, which not
188
+
data/Rakefile ADDED
@@ -0,0 +1,57 @@
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 = 'Silmarails'
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("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+ task default: :test
37
+
38
+ namespace :templates do
39
+ # desc "Copy all the templates from rspec to the application directory for customization. Already existing local copies will be overwritten"
40
+ task :rspec do
41
+ generators_lib = File.join(Gem.loaded_specs["rspec-rails"].full_gem_path, "lib/generators")
42
+ project_templates = "#{Rails.root}/lib/templates"
43
+
44
+ default_templates = { "rspec" => %w{controller helper integration mailer model observer scaffold view} }
45
+
46
+ default_templates.each do |type, names|
47
+ local_template_type_dir = File.join(project_templates, type)
48
+ FileUtils.mkdir_p local_template_type_dir
49
+
50
+ names.each do |name|
51
+ dst_name = File.join(local_template_type_dir, name)
52
+ src_name = File.join(generators_lib, type, name, "templates")
53
+ FileUtils.cp_r src_name, dst_name
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,4 @@
1
+ class window.MagicView
2
+ render: ->
3
+ cleanup: ->
4
+
@@ -0,0 +1,25 @@
1
+ pageLoad = ->
2
+ actionClassName = $('body').data('action-view')
3
+ window.currentView = try
4
+ eval("new #{actionClassName}()")
5
+ catch error
6
+ controllerClassName = $('body').data('controller-view')
7
+ window.currentView = try
8
+ eval("new #{controllerClassName}()")
9
+ catch error
10
+ new MagicView()
11
+ window.currentView.render()
12
+
13
+ $ ->
14
+ pageLoad()
15
+
16
+ # turbolinks
17
+ $(document).on 'page:load', pageLoad
18
+ $(document).on 'page:before-change', ->
19
+ window.currentView.cleanup()
20
+ true
21
+ $(document).on 'page:restore', ->
22
+ window.currentView.cleanup()
23
+ pageLoad()
24
+ true
25
+
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Copy all the overrided templates by silmarails
3
+
4
+ Example:
5
+ rails generate silmarails:install
6
+
7
+ This will create: a lot of template files for a lot of generators
8
+
@@ -0,0 +1,33 @@
1
+ module ActiveRecord
2
+ class Base
3
+ # this method returns the attributes to use on controller tests
4
+ def test_attributes
5
+ attributes.delete_if do |key, value|
6
+ ["id", "created_at", "updated_at"].include? key
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ def create_session(user = nil)
13
+ # You'll probably need to do something like this:
14
+ #
15
+ # controller.sign_in(user || FactoryGirl.create(:user))
16
+ #
17
+ # Or if you are using devise:
18
+ #
19
+ # sign_in(user || FactoryGirl.create(:user))
20
+ #
21
+ # If you don't need a user logged in, just leave this method as it is now
22
+ end
23
+
24
+ def valid_session_hash(user = nil)
25
+ # You'll probably need to do something like this:
26
+ #
27
+ # user ||= FactoryGirl.create(:user)
28
+ # {user_id: user.id}
29
+ #
30
+ # If you don't need a user logged in, just leave this method as it is now
31
+ {}
32
+ end
33
+
@@ -0,0 +1,22 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %> < <%= parent_class_name.classify %>
3
+ <% attributes.select(&:reference?).each do |attribute| -%>
4
+ belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %><%= ', required: true' if attribute.required? %>
5
+ <% end -%>
6
+ <% if attributes.any?(&:password_digest?) -%>
7
+ has_secure_password
8
+ <% end -%>
9
+ <%
10
+ attributes_to_show = attributes.reject(&:password_digest?)
11
+ title_attribute = attributes_to_show.find do |attr|
12
+ ["name", "title"].include? attr.name
13
+ end || attributes_to_show.first
14
+ -%>
15
+ <% if title_attribute.present? -%>
16
+ def to_title
17
+ <%= title_attribute.name %>
18
+ end
19
+ <% end -%>
20
+ end
21
+ <% end -%>
22
+
@@ -0,0 +1,11 @@
1
+ class window.<%= class_name %>View extends MagicView
2
+ render: ->
3
+ # override this method and initialize/bind your things for the index page
4
+ # but don't forget to always call super
5
+ super
6
+
7
+ cleanup: ->
8
+ # everything you initialize/bind on render, rather destroy/unbind in this
9
+ # method, and don't forget the super
10
+ super
11
+