jabysoft-bootstrap_generators 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +9 -0
  4. data/.rspec +2 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +41 -0
  9. data/Rakefile +6 -0
  10. data/app/assets/javascripts/jabysoft.js +1 -0
  11. data/app/assets/stylesheets/jabysoft.sass +38 -0
  12. data/app/assets/stylesheets/mixins.scss +68 -0
  13. data/app/views/layouts/admin.html.haml +46 -0
  14. data/app/views/layouts/application.html.haml +31 -0
  15. data/app/views/shared/_datepicker_field.html.haml +9 -0
  16. data/app/views/shared/_layout.html.haml +7 -0
  17. data/app/views/shared/_messages.html.haml +7 -0
  18. data/app/views/shared/_panel.html.haml +5 -0
  19. data/app/views/shared/_search_form.html.haml +6 -0
  20. data/app/views/shared/form/_error_messages.html.haml +6 -0
  21. data/app/views/shared/modals/_delete_confirmation.html.haml +17 -0
  22. data/bin/console +14 -0
  23. data/bin/setup +8 -0
  24. data/config/locales/en.yml +35 -0
  25. data/config/locales/pt-BR.yml +35 -0
  26. data/jabysoft-bootstrap_generators.gemspec +40 -0
  27. data/lib/generators/haml/scaffold/scaffold_generator.rb +35 -0
  28. data/lib/generators/jabysoft/setup/USAGE +19 -0
  29. data/lib/generators/jabysoft/setup/setup_generator.rb +57 -0
  30. data/lib/generators/jabysoft/setup/templates/.rspec +3 -0
  31. data/lib/generators/jabysoft/setup/templates/Gemfile +52 -0
  32. data/lib/generators/jabysoft/setup/templates/assets/stylesheets/bootstrap-variables.scss +876 -0
  33. data/lib/generators/jabysoft/setup/templates/layouts/admin.html.haml +46 -0
  34. data/lib/generators/jabysoft/setup/templates/layouts/application.html.haml +32 -0
  35. data/lib/generators/jabysoft/setup/templates/spec/rails_helper.rb +95 -0
  36. data/lib/generators/jabysoft/setup/templates/spec/spec_helper.rb +97 -0
  37. data/lib/generators/rspec/scaffold/scaffold_generator.rb +157 -0
  38. data/lib/jabysoft/bootstrap_generators.rb +15 -0
  39. data/lib/jabysoft/bootstrap_generators/version.rb +5 -0
  40. data/lib/templates/haml/scaffold/_form.html.haml +14 -0
  41. data/lib/templates/haml/scaffold/_index.html.haml +25 -0
  42. data/lib/templates/haml/scaffold/edit.html.haml +1 -0
  43. data/lib/templates/haml/scaffold/index.html.haml +1 -0
  44. data/lib/templates/haml/scaffold/new.html.haml +1 -0
  45. data/lib/templates/haml/scaffold/show.html.haml +1 -0
  46. data/lib/templates/rails/scaffold_controller/controller.rb +28 -0
  47. data/lib/templates/rspec/scaffold/controller_spec.rb +148 -0
  48. data/lib/templates/rspec/scaffold/model_spec.rb +14 -0
  49. data/lib/templates/rspec/scaffold/request_spec.rb +10 -0
  50. data/lib/templates/rspec/scaffold/routing_spec.rb +44 -0
  51. data/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.eot +0 -0
  52. data/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.svg +288 -0
  53. data/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf +0 -0
  54. data/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.woff +0 -0
  55. data/vendor/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2 +0 -0
  56. data/vendor/assets/images/.keep +0 -0
  57. data/vendor/assets/javascripts/bootstrap-sprockets.js +12 -0
  58. data/vendor/assets/javascripts/bootstrap.js +2377 -0
  59. data/vendor/assets/javascripts/bootstrap.min.js +7 -0
  60. data/vendor/assets/javascripts/bootstrap/affix.js +162 -0
  61. data/vendor/assets/javascripts/bootstrap/alert.js +94 -0
  62. data/vendor/assets/javascripts/bootstrap/button.js +125 -0
  63. data/vendor/assets/javascripts/bootstrap/carousel.js +237 -0
  64. data/vendor/assets/javascripts/bootstrap/collapse.js +212 -0
  65. data/vendor/assets/javascripts/bootstrap/dropdown.js +165 -0
  66. data/vendor/assets/javascripts/bootstrap/modal.js +339 -0
  67. data/vendor/assets/javascripts/bootstrap/popover.js +108 -0
  68. data/vendor/assets/javascripts/bootstrap/scrollspy.js +172 -0
  69. data/vendor/assets/javascripts/bootstrap/tab.js +155 -0
  70. data/vendor/assets/javascripts/bootstrap/tooltip.js +520 -0
  71. data/vendor/assets/javascripts/bootstrap/transition.js +59 -0
  72. data/vendor/assets/stylesheets/_bootstrap-compass.scss +9 -0
  73. data/vendor/assets/stylesheets/_bootstrap-mincer.scss +19 -0
  74. data/vendor/assets/stylesheets/_bootstrap-sprockets.scss +9 -0
  75. data/vendor/assets/stylesheets/_bootstrap.scss +56 -0
  76. data/vendor/assets/stylesheets/bootstrap/_alerts.scss +73 -0
  77. data/vendor/assets/stylesheets/bootstrap/_badges.scss +68 -0
  78. data/vendor/assets/stylesheets/bootstrap/_breadcrumbs.scss +28 -0
  79. data/vendor/assets/stylesheets/bootstrap/_button-groups.scss +244 -0
  80. data/vendor/assets/stylesheets/bootstrap/_buttons.scss +168 -0
  81. data/vendor/assets/stylesheets/bootstrap/_carousel.scss +270 -0
  82. data/vendor/assets/stylesheets/bootstrap/_close.scss +36 -0
  83. data/vendor/assets/stylesheets/bootstrap/_code.scss +69 -0
  84. data/vendor/assets/stylesheets/bootstrap/_component-animations.scss +37 -0
  85. data/vendor/assets/stylesheets/bootstrap/_dropdowns.scss +216 -0
  86. data/vendor/assets/stylesheets/bootstrap/_forms.scss +617 -0
  87. data/vendor/assets/stylesheets/bootstrap/_glyphicons.scss +307 -0
  88. data/vendor/assets/stylesheets/bootstrap/_grid.scss +84 -0
  89. data/vendor/assets/stylesheets/bootstrap/_input-groups.scss +171 -0
  90. data/vendor/assets/stylesheets/bootstrap/_jumbotron.scss +54 -0
  91. data/vendor/assets/stylesheets/bootstrap/_labels.scss +66 -0
  92. data/vendor/assets/stylesheets/bootstrap/_list-group.scss +130 -0
  93. data/vendor/assets/stylesheets/bootstrap/_media.scss +66 -0
  94. data/vendor/assets/stylesheets/bootstrap/_mixins.scss +40 -0
  95. data/vendor/assets/stylesheets/bootstrap/_modals.scss +150 -0
  96. data/vendor/assets/stylesheets/bootstrap/_navbar.scss +662 -0
  97. data/vendor/assets/stylesheets/bootstrap/_navs.scss +242 -0
  98. data/vendor/assets/stylesheets/bootstrap/_normalize.scss +424 -0
  99. data/vendor/assets/stylesheets/bootstrap/_pager.scss +54 -0
  100. data/vendor/assets/stylesheets/bootstrap/_pagination.scss +89 -0
  101. data/vendor/assets/stylesheets/bootstrap/_panels.scss +271 -0
  102. data/vendor/assets/stylesheets/bootstrap/_popovers.scss +131 -0
  103. data/vendor/assets/stylesheets/bootstrap/_print.scss +101 -0
  104. data/vendor/assets/stylesheets/bootstrap/_progress-bars.scss +87 -0
  105. data/vendor/assets/stylesheets/bootstrap/_responsive-embed.scss +35 -0
  106. data/vendor/assets/stylesheets/bootstrap/_responsive-utilities.scss +179 -0
  107. data/vendor/assets/stylesheets/bootstrap/_scaffolding.scss +161 -0
  108. data/vendor/assets/stylesheets/bootstrap/_tables.scss +234 -0
  109. data/vendor/assets/stylesheets/bootstrap/_theme.scss +291 -0
  110. data/vendor/assets/stylesheets/bootstrap/_thumbnails.scss +38 -0
  111. data/vendor/assets/stylesheets/bootstrap/_tooltip.scss +101 -0
  112. data/vendor/assets/stylesheets/bootstrap/_type.scss +298 -0
  113. data/vendor/assets/stylesheets/bootstrap/_utilities.scss +55 -0
  114. data/vendor/assets/stylesheets/bootstrap/_variables.scss +874 -0
  115. data/vendor/assets/stylesheets/bootstrap/_wells.scss +29 -0
  116. data/vendor/assets/stylesheets/bootstrap/mixins/_alerts.scss +14 -0
  117. data/vendor/assets/stylesheets/bootstrap/mixins/_background-variant.scss +12 -0
  118. data/vendor/assets/stylesheets/bootstrap/mixins/_border-radius.scss +18 -0
  119. data/vendor/assets/stylesheets/bootstrap/mixins/_buttons.scss +65 -0
  120. data/vendor/assets/stylesheets/bootstrap/mixins/_center-block.scss +7 -0
  121. data/vendor/assets/stylesheets/bootstrap/mixins/_clearfix.scss +22 -0
  122. data/vendor/assets/stylesheets/bootstrap/mixins/_forms.scss +88 -0
  123. data/vendor/assets/stylesheets/bootstrap/mixins/_gradients.scss +58 -0
  124. data/vendor/assets/stylesheets/bootstrap/mixins/_grid-framework.scss +81 -0
  125. data/vendor/assets/stylesheets/bootstrap/mixins/_grid.scss +122 -0
  126. data/vendor/assets/stylesheets/bootstrap/mixins/_hide-text.scss +21 -0
  127. data/vendor/assets/stylesheets/bootstrap/mixins/_image.scss +33 -0
  128. data/vendor/assets/stylesheets/bootstrap/mixins/_labels.scss +12 -0
  129. data/vendor/assets/stylesheets/bootstrap/mixins/_list-group.scss +32 -0
  130. data/vendor/assets/stylesheets/bootstrap/mixins/_nav-divider.scss +10 -0
  131. data/vendor/assets/stylesheets/bootstrap/mixins/_nav-vertical-align.scss +9 -0
  132. data/vendor/assets/stylesheets/bootstrap/mixins/_opacity.scss +8 -0
  133. data/vendor/assets/stylesheets/bootstrap/mixins/_pagination.scss +24 -0
  134. data/vendor/assets/stylesheets/bootstrap/mixins/_panels.scss +24 -0
  135. data/vendor/assets/stylesheets/bootstrap/mixins/_progress-bar.scss +10 -0
  136. data/vendor/assets/stylesheets/bootstrap/mixins/_reset-filter.scss +8 -0
  137. data/vendor/assets/stylesheets/bootstrap/mixins/_reset-text.scss +18 -0
  138. data/vendor/assets/stylesheets/bootstrap/mixins/_resize.scss +6 -0
  139. data/vendor/assets/stylesheets/bootstrap/mixins/_responsive-visibility.scss +21 -0
  140. data/vendor/assets/stylesheets/bootstrap/mixins/_size.scss +10 -0
  141. data/vendor/assets/stylesheets/bootstrap/mixins/_tab-focus.scss +9 -0
  142. data/vendor/assets/stylesheets/bootstrap/mixins/_table-row.scss +28 -0
  143. data/vendor/assets/stylesheets/bootstrap/mixins/_text-emphasis.scss +12 -0
  144. data/vendor/assets/stylesheets/bootstrap/mixins/_text-overflow.scss +8 -0
  145. data/vendor/assets/stylesheets/bootstrap/mixins/_vendor-prefixes.scss +222 -0
  146. metadata +316 -0
@@ -0,0 +1,46 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
5
+ %title= t('title.administration')
6
+ = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
7
+ = javascript_include_tag 'application', 'data-turbolinks-track' => true
8
+ = csrf_meta_tags
9
+ %body
10
+ %nav.navbar.navbar-inverse.navbar-static-top{role: 'navigation'}
11
+ .container-fluid
12
+ = link_to t('title.administration'), admin_root_path, class: 'navbar-brand'
13
+
14
+ %button{class: "navbar-toggle", "data-toggle" => "collapse", "data-target" => ".navHeaderCollapse"}
15
+ %span.glyphicon.glyphicon-th
16
+ #navbar.collapse.navbar-collapse.navHeaderCollapse
17
+ %ul.nav.navbar-nav.navbar-left
18
+ %li= link_to t('dashboard'), '#'
19
+ %li= link_to t('about'), '#'
20
+ %li.dropdown
21
+ %a.dropdown-toggle{src: '#', "data-toggle" => 'dropdown'}
22
+ = "Dropdown"
23
+ .glyphicon.glyphicon-chevron-down
24
+ %ul.dropdown-menu
25
+ %li= link_to 'First link', '#'
26
+
27
+ %ul.nav.navbar-nav.navbar-right
28
+ %li
29
+ .user-name User Name
30
+ .logout
31
+ = link_to t('logout'), '#', method: :delete, class: 'btn btn-default glyphicon glyphicon-off'
32
+ %li.user-avatar
33
+ = image_tag("icons/admin.png")
34
+
35
+ .container-fluid
36
+ .row
37
+ .col-lg-12
38
+ = render_flash_messages
39
+ .row
40
+ .col-lg-12
41
+ = yield
42
+
43
+ %footer.navbar.navbar-default.navbar-static-bottom
44
+ .container-fluid
45
+ %p.navbar-text
46
+ = "© Admin JabySoft #{Date.today.year} All rights reserved".html_safe
@@ -0,0 +1,32 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
5
+ %title= t('title.application')
6
+ = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
7
+ = javascript_include_tag 'application', 'data-turbolinks-track' => true
8
+ = csrf_meta_tags
9
+ %body
10
+ %nav.navbar.navbar-inverse.navbar-static-top{role: 'navigation'}
11
+ .container-fluid
12
+ = link_to t('title.application'), '#', class: 'navbar-brand'
13
+
14
+ %button{class: "navbar-toggle", "data-toggle" => "collapse", "data-target" => ".navHeaderCollapse"}
15
+ %span.glyphicon.glyphicon-th
16
+ .collapse.navbar-collapse.navHeaderCollapse
17
+ %ul.nav.navbar-nav.navbar-left
18
+ %li= link_to t('dashboard'), '#'
19
+ %li= link_to t('about'), '#'
20
+
21
+ .container-fluid
22
+ .row
23
+ .col-lg-12
24
+ = render_flash_messages
25
+ .row
26
+ .col-lg-12
27
+ = yield
28
+
29
+ %footer.navbar.navbar-default.navbar-static-bottom
30
+ .container-fluid
31
+ %p.navbar-text
32
+ = "© JabySoft #{Date.today.year} All rights reserved".html_safe
@@ -0,0 +1,95 @@
1
+ # It sends test coverage info to codacy.com
2
+ require 'codacy-coverage'
3
+ Codacy::Reporter.start
4
+
5
+ require 'simplecov'
6
+ SimpleCov.start :rails do
7
+ add_filter 'config/initializers'
8
+ end
9
+
10
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
11
+ ENV['RAILS_ENV'] ||= 'test'
12
+ require File.expand_path('../../config/environment', __FILE__)
13
+ # Prevent database truncation if the environment is production
14
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
15
+ require 'spec_helper'
16
+ require 'rspec/rails'
17
+ # Add additional requires below this line. Rails is not loaded until this point!
18
+ require 'shoulda/matchers'
19
+ Shoulda::Matchers.configure do |config|
20
+ config.integrate do |with|
21
+ with.test_framework :rspec
22
+ with.library :rails
23
+ end
24
+ end
25
+
26
+ # Requires supporting ruby files with custom matchers and macros, etc, in
27
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
28
+ # run as spec files by default. This means that files in spec/support that end
29
+ # in _spec.rb will both be required and run as specs, causing the specs to be
30
+ # run twice. It is recommended that you do not name files matching this glob to
31
+ # end with _spec.rb. You can configure this pattern with the --pattern
32
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
33
+ #
34
+ # The following line is provided for convenience purposes. It has the downside
35
+ # of increasing the boot-up time by auto-requiring all files in the support
36
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
37
+ # require only the support files necessary.
38
+ #
39
+ # Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
40
+
41
+ # Checks for pending migration and applies them before tests are run.
42
+ # If you are not using ActiveRecord, you can remove this line.
43
+ ActiveRecord::Migration.maintain_test_schema!
44
+
45
+ RSpec.configure do |config|
46
+
47
+ # DEVISE
48
+ config.include Devise::Test::ControllerHelpers, :type => :controller
49
+ # FACTORY-GIRL
50
+ config.include FactoryGirl::Syntax::Methods
51
+ # DatabaseCleaner
52
+ config.before(:suite) do
53
+ DatabaseCleaner.clean_with(:truncation)
54
+ end
55
+ config.before(:each) do
56
+ DatabaseCleaner.strategy = :transaction
57
+ end
58
+ config.before(:each, :js => true) do
59
+ DatabaseCleaner.strategy = :truncation
60
+ end
61
+ config.before(:each) do
62
+ DatabaseCleaner.start
63
+ end
64
+ config.after(:each) do
65
+ DatabaseCleaner.clean
66
+ end
67
+
68
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
69
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
70
+
71
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
72
+ # examples within a transaction, remove the following line or assign false
73
+ # instead of true.
74
+ config.use_transactional_fixtures = true
75
+
76
+ # RSpec Rails can automatically mix in different behaviours to your tests
77
+ # based on their file location, for example enabling you to call `get` and
78
+ # `post` in specs under `spec/controllers`.
79
+ #
80
+ # You can disable this behaviour by removing the line below, and instead
81
+ # explicitly tag your specs with their type, e.g.:
82
+ #
83
+ # RSpec.describe UsersController, :type => :controller do
84
+ # # ...
85
+ # end
86
+ #
87
+ # The different available types are documented in the features, such as in
88
+ # https://relishapp.com/rspec/rspec-rails/docs
89
+ config.infer_spec_type_from_file_location!
90
+
91
+ # Filter lines from Rails gems in backtraces.
92
+ config.filter_rails_from_backtrace!
93
+ # arbitrary gems may also be filtered via:
94
+ # config.filter_gems_from_backtrace("gem name")
95
+ end
@@ -0,0 +1,97 @@
1
+ require 'simplecov'
2
+ SimpleCov.start :rails do
3
+ add_filter 'config/initializers'
4
+ end
5
+
6
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
9
+ # this file to always be loaded, without a need to explicitly require it in any
10
+ # files.
11
+ #
12
+ # Given that it is always loaded, you are encouraged to keep this file as
13
+ # light-weight as possible. Requiring heavyweight dependencies from this file
14
+ # will add to the boot time of your test suite on EVERY test run, even for an
15
+ # individual file that may not need all of that loaded. Instead, consider making
16
+ # a separate helper file that requires the additional dependencies and performs
17
+ # the additional setup, and require it from the spec files that actually need
18
+ # it.
19
+ #
20
+ # The `.rspec` file also contains a few flags that are not defaults but that
21
+ # users commonly want.
22
+ #
23
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
24
+ RSpec.configure do |config|
25
+ # rspec-expectations config goes here. You can use an alternate
26
+ # assertion/expectation library such as wrong or the stdlib/minitest
27
+ # assertions if you prefer.
28
+ config.expect_with :rspec do |expectations|
29
+ # This option will default to `true` in RSpec 4. It makes the `description`
30
+ # and `failure_message` of custom matchers include text for helper methods
31
+ # defined using `chain`, e.g.:
32
+ # be_bigger_than(2).and_smaller_than(4).description
33
+ # # => "be bigger than 2 and smaller than 4"
34
+ # ...rather than:
35
+ # # => "be bigger than 2"
36
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
37
+ end
38
+
39
+ # rspec-mocks config goes here. You can use an alternate test double
40
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
41
+ config.mock_with :rspec do |mocks|
42
+ # Prevents you from mocking or stubbing a method that does not exist on
43
+ # a real object. This is generally recommended, and will default to
44
+ # `true` in RSpec 4.
45
+ mocks.verify_partial_doubles = true
46
+ end
47
+
48
+ # The settings below are suggested to provide a good initial experience
49
+ # with RSpec, but feel free to customize to your heart's content.
50
+ =begin
51
+ # This allows you to limit a spec run to individual examples or groups
52
+ # you care about by tagging them with `:focus` metadata. When nothing
53
+ # is tagged with `:focus`, all examples get run. RSpec also provides
54
+ # aliases for `it`, `describe`, and `context` that include `:focus`
55
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56
+ config.filter_run_when_matching :focus
57
+
58
+ # Allows RSpec to persist some state between runs in order to support
59
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
60
+ # you configure your source control system to ignore this file.
61
+ config.example_status_persistence_file_path = "spec/examples.txt"
62
+
63
+ # Limits the available syntax to the non-monkey patched syntax that is
64
+ # recommended. For more details, see:
65
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
66
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
67
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
68
+ config.disable_monkey_patching!
69
+
70
+ # Many RSpec users commonly either run the entire suite or an individual
71
+ # file, and it's useful to allow more verbose output when running an
72
+ # individual spec file.
73
+ if config.files_to_run.one?
74
+ # Use the documentation formatter for detailed output,
75
+ # unless a formatter has already been configured
76
+ # (e.g. via a command-line flag).
77
+ config.default_formatter = 'doc'
78
+ end
79
+
80
+ # Print the 10 slowest examples and example groups at the
81
+ # end of the spec run, to help surface which specs are running
82
+ # particularly slow.
83
+ config.profile_examples = 10
84
+
85
+ # Run specs in random order to surface order dependencies. If you find an
86
+ # order dependency and want to debug it, you can fix the order by providing
87
+ # the seed, which is printed after each run.
88
+ # --seed 1234
89
+ config.order = :random
90
+
91
+ # Seed global randomization in this process using the `--seed` CLI option.
92
+ # Setting this allows you to use `--seed` to deterministically reproduce
93
+ # test failures related to randomization by passing the same `--seed` value
94
+ # as the one that triggered the failure.
95
+ Kernel.srand config.seed
96
+ =end
97
+ end
@@ -0,0 +1,157 @@
1
+ require 'generators/rspec'
2
+ require 'rails/generators/resource_helpers'
3
+
4
+ module Rspec
5
+ module Generators
6
+ # @private
7
+ class ScaffoldGenerator < Base
8
+ include ::Rails::Generators::ResourceHelpers
9
+ source_paths << File.expand_path("../../helper/templates", __FILE__)
10
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
11
+
12
+ class_option :orm, :desc => "ORM used to generate the controller"
13
+ class_option :template_engine, :desc => "Template engine to generate view files"
14
+ class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
15
+
16
+ class_option :controller_specs, :type => :boolean, :default => true, :desc => "Generate controller specs"
17
+ class_option :view_specs, :type => :boolean, :default => true, :desc => "Generate view specs"
18
+ class_option :helper_specs, :type => :boolean, :default => true, :desc => "Generate helper specs"
19
+ class_option :routing_specs, :type => :boolean, :default => true, :desc => "Generate routing specs"
20
+
21
+ def generate_controller_spec
22
+ return unless options[:controller_specs]
23
+
24
+ template_file = File.join(
25
+ 'spec/controllers',
26
+ controller_class_path,
27
+ "#{controller_file_name}_controller_spec.rb"
28
+ )
29
+ template 'controller_spec.rb', template_file
30
+ end
31
+
32
+ def generate_routing_spec
33
+ return unless options[:routing_specs]
34
+
35
+ template_file = File.join(
36
+ 'spec/routing',
37
+ controller_class_path,
38
+ "#{controller_file_name}_routing_spec.rb"
39
+ )
40
+ template 'routing_spec.rb', template_file
41
+ end
42
+
43
+ hook_for :integration_tool, :as => :integration
44
+
45
+ protected
46
+
47
+ def copy_view(view)
48
+ template "#{view}_spec.rb",
49
+ File.join("spec/views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb")
50
+ end
51
+
52
+ def formatted_hash(hash)
53
+ formatted = hash.inspect
54
+ formatted.gsub!("{", "{ ")
55
+ formatted.gsub!("}", " }")
56
+ formatted.gsub!("=>", " => ")
57
+ formatted
58
+ end
59
+
60
+ # support for namespaced-resources
61
+ def ns_file_name
62
+ ns_parts.empty? ? file_name : "#{ns_parts[0].underscore}_#{ns_parts[1].singularize.underscore}"
63
+ end
64
+
65
+ # support for namespaced-resources
66
+ def ns_table_name
67
+ ns_parts.empty? ? table_name : "#{ns_parts[0].underscore}/#{ns_parts[1].tableize}"
68
+ end
69
+
70
+ def ns_parts
71
+ @ns_parts ||= begin
72
+ matches = ARGV[0].to_s.match(/\A(\w+)(?:\/|::)(\w+)/)
73
+ matches ? [matches[1], matches[2]] : []
74
+ end
75
+ end
76
+
77
+ # Returns the name of the mock. For example, if the file name is user,
78
+ # it returns mock_user.
79
+ #
80
+ # If a hash is given, it uses the hash key as the ORM method and the
81
+ # value as response. So, for ActiveRecord and file name "User":
82
+ #
83
+ # mock_file_name(:save => true)
84
+ # #=> mock_user(:save => true)
85
+ #
86
+ # If another ORM is being used and another method instead of save is
87
+ # called, it will be the one used.
88
+ #
89
+ def mock_file_name(hash = nil)
90
+ if hash
91
+ method, and_return = hash.to_a.first
92
+ method = orm_instance.send(method).split('.').last.gsub(/\(.*?\)/, '')
93
+ "mock_#{ns_file_name}(:#{method} => #{and_return})"
94
+ else
95
+ "mock_#{ns_file_name}"
96
+ end
97
+ end
98
+
99
+ # Receives the ORM chain and convert to expects. For ActiveRecord:
100
+ #
101
+ # should! orm_class.find(User, "37")
102
+ # #=> User.should_receive(:find).with(37)
103
+ #
104
+ # For Datamapper:
105
+ #
106
+ # should! orm_class.find(User, "37")
107
+ # #=> User.should_receive(:get).with(37)
108
+ #
109
+ def should_receive(chain)
110
+ stub_or_should_chain(:should_receive, chain)
111
+ end
112
+
113
+ # Receives the ORM chain and convert to stub. For ActiveRecord:
114
+ #
115
+ # stub orm_class.find(User, "37")
116
+ # #=> User.stub(:find).with(37)
117
+ #
118
+ # For Datamapper:
119
+ #
120
+ # stub orm_class.find(User, "37")
121
+ # #=> User.stub(:get).with(37)
122
+ #
123
+ def stub(chain)
124
+ stub_or_should_chain(:stub, chain)
125
+ end
126
+
127
+ def stub_or_should_chain(mode, chain)
128
+ receiver, method = chain.split(".")
129
+ method.gsub!(/\((.*?)\)/, '')
130
+
131
+ response = "#{receiver}.#{mode}(:#{method})"
132
+ response << ".with(#{$1})" unless $1.blank?
133
+ response
134
+ end
135
+
136
+ def value_for(attribute)
137
+ raw_value_for(attribute).inspect
138
+ end
139
+
140
+ def raw_value_for(attribute)
141
+ case attribute.type
142
+ when :string
143
+ attribute.name.titleize
144
+ when :integer, :float
145
+ @attribute_id_map ||= {}
146
+ @attribute_id_map[attribute] ||= @attribute_id_map.keys.size.next + attribute.default
147
+ else
148
+ attribute.default
149
+ end
150
+ end
151
+
152
+ def banner
153
+ self.class.banner
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,15 @@
1
+ require "jabysoft/bootstrap_generators/version"
2
+ require 'rails/engine'
3
+
4
+ module Jabysoft
5
+ module BootstrapGenerators
6
+ class Engine < ::Rails::Engine
7
+ config.app_generators do |g|
8
+ g.templates.unshift File.expand_path('../../templates', __FILE__)
9
+ g.orm :active_record
10
+ g.template_engine :haml
11
+ g.test_framework :rspec, fixture: false
12
+ end
13
+ end
14
+ end
15
+ end