katapult 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +11 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +122 -0
  9. data/Rakefile +14 -0
  10. data/bin/katapult +44 -0
  11. data/features/binary.feature +48 -0
  12. data/features/configuration.feature +24 -0
  13. data/features/katapult.feature +201 -0
  14. data/features/model.feature +203 -0
  15. data/features/navigation.feature +80 -0
  16. data/features/step_definitions/db_steps.rb +8 -0
  17. data/features/step_definitions/file_steps.rb +14 -0
  18. data/features/step_definitions/katapult_steps.rb +14 -0
  19. data/features/step_definitions/rails_steps.rb +44 -0
  20. data/features/step_definitions/test_steps.rb +7 -0
  21. data/features/support/env.rb +16 -0
  22. data/features/wui.feature +319 -0
  23. data/katapult.gemspec +35 -0
  24. data/katapult.png +0 -0
  25. data/lib/generators/katapult/basics/basics_generator.rb +95 -0
  26. data/lib/generators/katapult/basics/templates/Gemfile +76 -0
  27. data/lib/generators/katapult/basics/templates/app/assets/stylesheets/application.css.sass +6 -0
  28. data/lib/generators/katapult/basics/templates/app/assets/stylesheets/application/blocks/_all.css.sass +4 -0
  29. data/lib/generators/katapult/basics/templates/app/assets/stylesheets/application/blocks/_items.css.sass +11 -0
  30. data/lib/generators/katapult/basics/templates/app/assets/stylesheets/application/blocks/_layout.css.sass +26 -0
  31. data/lib/generators/katapult/basics/templates/app/assets/stylesheets/application/blocks/_navigation.css.sass +11 -0
  32. data/lib/generators/katapult/basics/templates/app/assets/stylesheets/application/blocks/_tools.css.sass +12 -0
  33. data/lib/generators/katapult/basics/templates/config/database.sample.yml +16 -0
  34. data/lib/generators/katapult/basics/templates/config/database.yml +13 -0
  35. data/lib/generators/katapult/basics/templates/config/spring.rb +3 -0
  36. data/lib/generators/katapult/basics/templates/features/support/env-custom.rb +3 -0
  37. data/lib/generators/katapult/basics/templates/features/support/paths.rb +47 -0
  38. data/lib/generators/katapult/cucumber_features/cucumber_features_generator.rb +23 -0
  39. data/lib/generators/katapult/cucumber_features/templates/feature.feature +59 -0
  40. data/lib/generators/katapult/haml/haml_generator.rb +90 -0
  41. data/lib/generators/katapult/haml/templates/_form.html.haml +38 -0
  42. data/lib/generators/katapult/haml/templates/app/views/layouts/application.html.haml +25 -0
  43. data/lib/generators/katapult/haml/templates/custom_action.html.haml +5 -0
  44. data/lib/generators/katapult/haml/templates/edit.html.haml +4 -0
  45. data/lib/generators/katapult/haml/templates/index.html.haml +29 -0
  46. data/lib/generators/katapult/haml/templates/new.html.haml +4 -0
  47. data/lib/generators/katapult/haml/templates/show.html.haml +41 -0
  48. data/lib/generators/katapult/install/install_generator.rb +14 -0
  49. data/lib/generators/katapult/install/templates/lib/katapult/application_model.rb +18 -0
  50. data/lib/generators/katapult/model/model_generator.rb +59 -0
  51. data/lib/generators/katapult/model/templates/app/models/shared/does_flag.rb +32 -0
  52. data/lib/generators/katapult/model/templates/model.rb +21 -0
  53. data/lib/generators/katapult/model_specs/model_specs_generator.rb +51 -0
  54. data/lib/generators/katapult/model_specs/templates/model_spec.rb +34 -0
  55. data/lib/generators/katapult/navigation/navigation_generator.rb +25 -0
  56. data/lib/generators/katapult/navigation/templates/app/models/navigation.rb +12 -0
  57. data/lib/generators/katapult/transform/transform_generator.rb +47 -0
  58. data/lib/generators/katapult/w_u_i/templates/_route.rb +13 -0
  59. data/lib/generators/katapult/w_u_i/templates/controller.rb +106 -0
  60. data/lib/generators/katapult/w_u_i/w_u_i_generator.rb +57 -0
  61. data/lib/katapult.rb +5 -0
  62. data/lib/katapult/action.rb +44 -0
  63. data/lib/katapult/application_model.rb +45 -0
  64. data/lib/katapult/attribute.rb +83 -0
  65. data/lib/katapult/element.rb +72 -0
  66. data/lib/katapult/generator.rb +28 -0
  67. data/lib/katapult/model.rb +33 -0
  68. data/lib/katapult/navigation.rb +22 -0
  69. data/lib/katapult/parser.rb +39 -0
  70. data/lib/katapult/util.rb +16 -0
  71. data/lib/katapult/version.rb +3 -0
  72. data/lib/katapult/wui.rb +77 -0
  73. data/script/console +16 -0
  74. data/spec/action_spec.rb +44 -0
  75. data/spec/attribute_spec.rb +48 -0
  76. data/spec/model_spec.rb +18 -0
  77. data/spec/spec_helper.rb +19 -0
  78. data/spec/util_spec.rb +23 -0
  79. data/spec/wui_spec.rb +49 -0
  80. metadata +253 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b262aea45a6e72401c0cee7d558e0320e3fe4a1
4
+ data.tar.gz: c252ae0b85dd9bd0cf682910a22212bff6058e70
5
+ SHA512:
6
+ metadata.gz: 9a96e6f9ab0445e68bbf35bfa69a8dd2c9122ed212bc6c086a4f402ca57a11d717b5885c805702ba237b109e2439a5be06cefdfcba28eea4b7947c66f2cf39d9
7
+ data.tar.gz: b1ee95eb5749a091c3e9d4ed3dd95a209e816cd6c92dfd313a27df545ffb2bac83252988ea0b4b50f8cd21578109fa94968d658a6d9946adc39f07c252692674
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .pt_project_id
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1 @@
1
+ 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in katapult.gemspec
4
+ gemspec
@@ -0,0 +1,11 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'cucumber' do
5
+ watch(%r{^features/.+\.feature$})
6
+ watch(%r{^features/support/.+$}) { 'features' }
7
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
8
+
9
+ watch(%r{^lib/generators/katapult/.+/.+_generator\.rb$}) { 'features/katapult.feature:12' }
10
+ watch(%r{^lib/katapult/.+\.rb$}) { 'features/katapult.feature:12' }
11
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Dominik
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,122 @@
1
+ # Katapult
2
+
3
+ <img src="katapult.png" width="200px" align="right" />
4
+
5
+
6
+ `Katapult` is a kickstart generator for Rails applications. It creates
7
+ application basics and generates (makandra-flavored) code from an application
8
+ model, significantly speeding up the initial phase of a Rails project.
9
+
10
+ `Katapult` will always support current versions of Ruby and Rails, currently
11
+ Rails 4.1 and Ruby 2.1.
12
+
13
+
14
+ ## Installation
15
+
16
+ As `katapult` is designed to *start* Rails applications, it works best with a
17
+ clean new Rails app. To create one, run
18
+
19
+ katapult target MY_APPLICATION_NAME
20
+
21
+ This will add the `katapult` gem to the Gemfile and then integrate `katapult`
22
+ by running
23
+
24
+ rails generate katapult:install
25
+ rails generate katapult:basics
26
+
27
+
28
+ It will install application basics, such as a `database.yml`, basics styles as
29
+ well as RSpec and Cucumber and prepare `lib/katapult/application_model.rb`
30
+ where you will draft your application.
31
+
32
+ ### Manual installation
33
+ You may also integrate the gem into an existing Rails application. Just add it to the Gemfile and run the generators stated above.
34
+
35
+
36
+ ## Usage
37
+
38
+ After installation, you find a file `lib/katapult/application_model.rb` where
39
+ you will define the properties of your application. Inside this file, use
40
+ `katapult`'s simple DSL (domain specific language) to express yourself.
41
+
42
+ The DSL consists of elements, e.g. Model or WUI (which stands for *Web User
43
+ Interface*). Each `katapult` element has the same syntax, taking a name,
44
+ options, and a block:
45
+
46
+ element_type 'name', options: 'example' do |element|
47
+ element.some_method
48
+ end
49
+
50
+
51
+ ### Model
52
+ Takes a name and a block:
53
+
54
+ model 'Customer' do |customer|
55
+ # ...
56
+ end
57
+
58
+
59
+ #### Attribute
60
+ Defined on Model. Takes a name and options:
61
+
62
+ model.attr :email
63
+ model.attr :age, type: :integer, assignable_values: 18..99, allow_blank: true
64
+ model.attr :income, type: :money
65
+ model.attr :homepage, type: :url, default: 'http://www.makandra.de'
66
+ model.attr :locked, type: :flag, default: false
67
+
68
+
69
+ ### WUI (Web User Interface)
70
+ Takes a name, options and a block:
71
+
72
+ wui 'Customer', model: 'User' do |wui|
73
+ # ...
74
+ end
75
+
76
+
77
+ #### Action
78
+ Defined on WUI. Takes a name and options:
79
+
80
+ wui.action :index
81
+ wui.action :show
82
+ wui.action :create # also creates :new
83
+ wui.action :update # also creates :edit
84
+ wui.action :destroy
85
+ wui.crud # creates all the standard rails actions above
86
+ wui.action :custom_action, method: :post, scope: :member
87
+ wui.action :other_action, method: :get, scope: :collection
88
+
89
+
90
+ ### Navigation
91
+ Takes a name, will generate a navigation with links to the index pages of all
92
+ WUIs.
93
+
94
+ navigation :main
95
+
96
+
97
+ ## Contributing
98
+
99
+ <!-- 1. Fork it ( http://github.com/<my-github-username>/katapult/fork )
100
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
101
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
102
+ 4. Push to the branch (`git push origin my-new-feature`)
103
+ 5. Create new Pull Request -->
104
+
105
+ `Katapult` caches a pristine Rails application inside its `tmp/` directory to
106
+ speed up test runs. Keep this in mind, as it may lead to caching issues when
107
+ switching Ruby versions or installing a new version of the Rails gem.
108
+
109
+ Since `katapult` has full-stack integration tests, it requires a MySQL account.
110
+ Create a dedicated account on your MySQL server by running this command in a
111
+ MySQL console (as-is):
112
+
113
+ GRANT ALL ON *.* TO 'katapult'@'localhost' IDENTIFIED BY 'secret';
114
+
115
+ The user `katapult` is hereby granted any action (SELECT, UPDATE, etc. except
116
+ for granting privileges) on any database and table (`*.*`).
117
+
118
+
119
+ ## Credits
120
+
121
+ Development: Dominik Schöler from [makandra](makandra.com)<br />
122
+ Katapult image: [Nemo](http://pixabay.com/de/katapult-30061)
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'cucumber/rake/task'
4
+ require 'rspec/core/rake_task'
5
+
6
+ task :default => :tests
7
+
8
+ task :tests => [:spec, :features]
9
+
10
+ Cucumber::Rake::Task.new(:features) do |t|
11
+ t.cucumber_opts = "features --format pretty"
12
+ end
13
+
14
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/katapult/util'
4
+
5
+ case (command = ARGV.shift)
6
+ when 'target'
7
+ app_name = ARGV.shift
8
+
9
+ puts 'Creating new Rails application ...'
10
+ system "rails new #{app_name} --skip-test-unit --skip-bundle --database mysql"
11
+
12
+ Dir.chdir app_name
13
+
14
+ puts
15
+ puts 'Initializing git repository ...'
16
+ system 'git init'
17
+ Katapult::Util.git_commit "rails new #{app_name}"
18
+
19
+ puts
20
+ puts 'Installing katapult ...'
21
+ File.open('Gemfile', 'a') do |file|
22
+ file.puts "gem 'katapult'#{ ENV['KATAPULT_GEMFILE_OPTIONS'] }"
23
+ end
24
+ system 'bundle install'
25
+ system 'bundle exec rails generate katapult:install'
26
+ Katapult::Util.git_commit 'rails generate katapult:install'
27
+
28
+ puts
29
+ puts 'Generating katapult basics ...'
30
+ system 'bundle exec rails generate katapult:basics'
31
+ Katapult::Util.git_commit 'rails generate katapult:basics'
32
+
33
+ puts
34
+ puts 'Done.'
35
+
36
+ when 'fire'
37
+ app_model_path = 'lib/katapult/application_model.rb'
38
+
39
+ puts 'Loading katapult ...'
40
+ system 'bin/rails generate katapult:transform ' + app_model_path
41
+
42
+ else
43
+ puts 'Usage: katapult [target APP_NAME | fire]'
44
+ end
@@ -0,0 +1,48 @@
1
+ Feature: Katapult binary `katapult`
2
+
3
+ Scenario: Start new Rails application
4
+ Given The default aruba timeout is 120 seconds
5
+
6
+ When I successfully run `katapult target binary_test`
7
+ Then the output should contain "Creating new Rails application"
8
+ And the output should contain "Installing katapult"
9
+ And the output should contain "Generating katapult basics"
10
+ And the output should contain "Done."
11
+
12
+ When I cd to "binary_test"
13
+
14
+ # test whether katapult is installed
15
+ Then the file "Gemfile" should contain "gem 'katapult'"
16
+ And a file named "lib/katapult/application_model.rb" should exist
17
+
18
+ # test whether the application is already bundled
19
+ When I run `bundle check`
20
+ Then the output should contain "The Gemfile's dependencies are satisfied"
21
+
22
+ # test whether katapult made git commits
23
+ When I run `git log`
24
+ Then the output should contain "rails new binary_test"
25
+ And the output should contain "rails generate katapult:install"
26
+ And the output should contain "rails generate katapult:basics"
27
+ And the output should contain "Author: katapult <katapult@makandra.com>"
28
+
29
+
30
+ Scenario: Forget to pass application name
31
+ When I run `katapult target # without app name`
32
+ Then the output should contain "No value provided for required arguments 'app_path'"
33
+
34
+
35
+ Scenario: Run without arguments
36
+ When I run `katapult # without arguments`
37
+ Then the output should contain "Usage: katapult [target APP_NAME | fire]"
38
+
39
+
40
+ Scenario: Transform the application model
41
+ Given a pristine Rails application
42
+ And I install katapult
43
+ And I generate katapult basics
44
+
45
+ When I run `katapult fire`
46
+ Then the output should contain "Loading katapult"
47
+ And the output should contain "parse lib/katapult/application_model"
48
+ And the output should contain "render into katapult_test_app"
@@ -0,0 +1,24 @@
1
+ Feature: Configure katapult
2
+
3
+ Background:
4
+ Given a pristine Rails application
5
+ And I install katapult
6
+ And I generate katapult basics
7
+
8
+
9
+ Scenario: Custom model template
10
+ When I overwrite "lib/katapult/application_model.rb" with:
11
+ """
12
+ model 'Car'
13
+ """
14
+ And a file named "lib/templates/katapult/model/model.rb" with:
15
+ """
16
+ # custom model template for <%= class_name %>
17
+
18
+ """
19
+ And I successfully transform the application model
20
+ Then the file "app/models/car.rb" should contain exactly:
21
+ """
22
+ # custom model template for Car
23
+
24
+ """
@@ -0,0 +1,201 @@
1
+ Feature: Katapult in general
2
+
3
+ Background:
4
+ Given a pristine Rails application
5
+
6
+
7
+ Scenario: Install katapult
8
+ When I install katapult
9
+ Then the file "lib/katapult/application_model.rb" should contain exactly:
10
+ """
11
+ # Here you define the fundamentals of your application.
12
+ #
13
+ # Add a model:
14
+ # model 'customer' do |customer|
15
+ # customer.attr :name
16
+ # customer.attr :birth, type: :date
17
+ # customer.attr :email
18
+ # end
19
+ #
20
+ # Add a web user interface:
21
+ # wui 'customer' do |wui|
22
+ # wui.action :index
23
+ # wui.action :show
24
+ # wui.action :lock, scope: :member, method: :post
25
+ # end
26
+ #
27
+ # Add navigation
28
+ # navigation :main
29
+
30
+ """
31
+
32
+
33
+ Scenario: Generate basic files and settings
34
+ Given I install katapult
35
+ When I generate katapult basics
36
+ Then the file "Gemfile" should contain exactly:
37
+ """
38
+ source 'https://rubygems.org'
39
+
40
+ # from original Gemfile
41
+ gem 'rails', '4.1.0'
42
+ gem 'mysql2'
43
+ gem 'jquery-rails'
44
+ gem 'jbuilder', '~> 2.0'
45
+ gem 'spring', group: :development
46
+ gem 'katapult', path: '../../..'
47
+
48
+ # engines
49
+ gem 'haml-rails'
50
+
51
+ # internal
52
+ gem 'exception_notification'
53
+ gem 'breach-mitigation-rails'
54
+
55
+ # better coding
56
+ gem 'modularity'
57
+ gem 'edge_rider'
58
+ gem 'andand'
59
+
60
+ # models
61
+ gem 'has_defaults'
62
+ gem 'assignable_values'
63
+
64
+ # gem 'carrierwave'
65
+ # gem 'mini_magick'
66
+
67
+ # gem 'spreadsheet'
68
+ # gem 'vcard'
69
+
70
+ # views
71
+ # gem 'simple_form'
72
+ # gem 'nested_form'
73
+ gem 'will_paginate'
74
+ gem 'makandra-navy', require: 'navy'
75
+
76
+ # assets
77
+ gem 'bootstrap-sass'
78
+ gem 'sass-rails'
79
+ gem 'autoprefixer-rails'
80
+ gem 'coffee-rails'
81
+ gem 'uglifier'
82
+ gem 'compass-rails'
83
+ gem 'compass-rgbapng'
84
+
85
+ group :development do
86
+ gem 'query_diet'
87
+ gem 'better_errors'
88
+ gem 'binding_of_caller'
89
+ gem 'thin'
90
+
91
+ gem 'guard-livereload', require: false
92
+ gem 'rack-livereload'
93
+ gem 'spring-commands-rspec'
94
+ gem 'spring-commands-cucumber'
95
+ end
96
+
97
+ group :development, :test do
98
+ gem 'byebug'
99
+ gem 'factory_girl_rails'
100
+ gem 'rspec-rails'
101
+ end
102
+
103
+ group :test do
104
+ gem 'parallel_tests'
105
+ gem 'database_cleaner'
106
+ gem 'timecop'
107
+ gem 'launchy'
108
+
109
+ gem 'capybara'
110
+ gem 'cucumber-rails', require: false
111
+ gem 'cucumber_factory'
112
+ gem 'cucumber_spinner'
113
+ gem 'selenium-webdriver'
114
+ gem 'spreewald'
115
+
116
+ gem 'rspec_candy'
117
+ gem 'shoulda-matchers', require: false
118
+ end
119
+
120
+ """
121
+
122
+ And the file "config/database.yml" should contain exactly:
123
+ """
124
+ common: &common
125
+ adapter: mysql2
126
+ encoding: utf8
127
+ username: katapult
128
+ password: secret
129
+
130
+ development:
131
+ <<: *common
132
+ database: katapult_test_app_development
133
+
134
+ test: &test
135
+ <<: *common
136
+ database: katapult_test_app_test<%= ENV['TEST_ENV_NUMBER'] %>
137
+
138
+ cucumber:
139
+ <<: *test
140
+ """
141
+ And the file "config/database.sample.yml" should contain exactly:
142
+ """
143
+ common: &common
144
+ adapter: mysql2
145
+ encoding: utf8
146
+ username: root
147
+ password:
148
+
149
+ development:
150
+ <<: *common
151
+ database: katapult_test_app_development
152
+
153
+ test: &test
154
+ <<: *common
155
+ database: katapult_test_app_test<%= ENV['TEST_ENV_NUMBER'] %>
156
+
157
+ cucumber:
158
+ <<: *test
159
+
160
+ """
161
+
162
+ And the file "features/support/env-custom.rb" should contain:
163
+ """
164
+ require 'rspec_candy/all'
165
+ require 'spreewald/all_steps'
166
+ """
167
+ And a file named "features/support/paths.rb" should exist
168
+ And the file "spec/rails_helper.rb" should contain:
169
+ """
170
+ require 'rspec/rails'
171
+ require 'shoulda/matchers'
172
+ """
173
+
174
+
175
+
176
+ # styles
177
+ And the file "app/assets/stylesheets/application.css.sass" should contain:
178
+ """
179
+ @import compass
180
+ @import bootstrap
181
+
182
+ @import application/blocks/all
183
+
184
+ """
185
+ And the file "app/assets/stylesheets/application/blocks/_all.css.sass" should contain exactly:
186
+ """
187
+ @import items
188
+ @import layout
189
+ @import navigation
190
+ @import tools
191
+
192
+ """
193
+ And a file named "app/assets/stylesheets/application/blocks/_items.css.sass" should exist
194
+ And a file named "app/assets/stylesheets/application/blocks/_layout.css.sass" should exist
195
+ And a file named "app/assets/stylesheets/application/blocks/_navigation.css.sass" should exist
196
+ And a file named "app/assets/stylesheets/application/blocks/_tools.css.sass" should exist
197
+
198
+ # And the file "config/deploy.rb" should contain exactly:
199
+ # """
200
+ # stages
201
+ # """