katapult 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +5 -5
  2. data/.rspec +1 -0
  3. data/.ruby-version +1 -1
  4. data/Gemfile +9 -0
  5. data/README.md +122 -94
  6. data/Rakefile +13 -0
  7. data/bin/katapult +59 -25
  8. data/features/application_model.feature +55 -0
  9. data/features/authenticate.feature +88 -62
  10. data/features/basics.feature +64 -402
  11. data/features/binary.feature +56 -42
  12. data/features/configuration.feature +4 -4
  13. data/features/model.feature +21 -30
  14. data/features/navigation.feature +35 -48
  15. data/features/step_definitions/aruba_steps.rb +3 -0
  16. data/features/step_definitions/katapult_steps.rb +307 -8
  17. data/features/step_definitions/rails_steps.rb +74 -14
  18. data/features/step_definitions/test_steps.rb +5 -5
  19. data/features/step_definitions/version_steps.rb +22 -0
  20. data/features/support/env.rb +11 -3
  21. data/features/{wui.feature → web_ui.feature} +175 -148
  22. data/katapult.gemspec +8 -13
  23. data/lib/generators/katapult/app_model/app_model_generator.rb +12 -0
  24. data/lib/generators/katapult/app_model/templates/lib/katapult/application_model.rb +40 -0
  25. data/lib/generators/katapult/basics/basics_generator.rb +186 -51
  26. data/lib/generators/katapult/basics/templates/.browserslistrc +1 -0
  27. data/lib/generators/katapult/basics/templates/.gitignore +20 -21
  28. data/lib/generators/katapult/basics/templates/.rspec_parallel +3 -0
  29. data/lib/generators/katapult/basics/templates/Capfile +5 -1
  30. data/lib/generators/katapult/basics/templates/Gemfile +23 -34
  31. data/lib/generators/katapult/basics/templates/Guardfile +0 -12
  32. data/lib/generators/katapult/basics/templates/app/controllers/errors_controller.rb +9 -0
  33. data/lib/generators/katapult/basics/templates/app/helpers/unpoly_helper.rb +13 -0
  34. data/lib/generators/katapult/{haml → basics}/templates/app/views/layouts/_flashes.html.haml +1 -1
  35. data/lib/generators/katapult/basics/templates/app/views/layouts/_menu_bar.html.haml.tt +12 -0
  36. data/lib/generators/katapult/basics/templates/app/views/layouts/application.html.haml.tt +25 -0
  37. data/lib/generators/katapult/basics/templates/app/webpack/assets/images/.keep +0 -0
  38. data/lib/generators/katapult/basics/templates/app/webpack/assets/index.js +16 -0
  39. data/lib/generators/katapult/basics/templates/app/webpack/assets/javascripts/application.js +0 -0
  40. data/lib/generators/katapult/basics/templates/app/webpack/assets/javascripts/bootstrap.js +12 -0
  41. data/lib/generators/katapult/basics/templates/app/webpack/assets/javascripts/compilers/.keep +0 -0
  42. data/lib/generators/katapult/basics/templates/app/webpack/assets/javascripts/macros/content_link.js +17 -0
  43. data/lib/generators/katapult/basics/templates/app/webpack/assets/javascripts/macros/modal_link.js +17 -0
  44. data/lib/generators/katapult/basics/templates/app/webpack/assets/javascripts/unpoly.js +9 -0
  45. data/lib/generators/katapult/basics/templates/app/webpack/assets/stylesheets/_definitions.sass +25 -0
  46. data/lib/generators/katapult/basics/templates/app/webpack/assets/stylesheets/_environment.sass +2 -0
  47. data/lib/generators/katapult/basics/templates/app/webpack/assets/stylesheets/_mixins.sass +3 -0
  48. data/lib/generators/katapult/basics/templates/app/webpack/assets/stylesheets/blocks/.keep +0 -0
  49. data/lib/generators/katapult/basics/templates/app/webpack/assets/stylesheets/custom_bootstrap.sass +50 -0
  50. data/lib/generators/katapult/basics/templates/app/webpack/assets/stylesheets/ext/.keep +0 -0
  51. data/lib/generators/katapult/basics/templates/app/webpack/assets/stylesheets/ext/bootstrap/navbar.sass +83 -0
  52. data/lib/generators/katapult/basics/templates/app/webpack/assets/stylesheets/theme.sass +11 -0
  53. data/lib/generators/katapult/basics/templates/app/webpack/assets/stylesheets/unpoly.sass +2 -0
  54. data/lib/generators/katapult/basics/templates/app/webpack/packs/application.js +13 -0
  55. data/lib/generators/katapult/basics/templates/config/database.sample.yml +1 -1
  56. data/lib/generators/katapult/basics/templates/config/deploy.rb +3 -4
  57. data/lib/generators/katapult/basics/templates/config/environments/staging.rb +5 -0
  58. data/lib/generators/katapult/basics/templates/config/initializers/better_errors.rb +23 -0
  59. data/lib/generators/katapult/basics/templates/config/initializers/exception_notification.rb.tt +1 -1
  60. data/lib/generators/katapult/basics/templates/config/initializers/ext.rb +1 -1
  61. data/lib/generators/katapult/basics/templates/config/webpack/loaders/unpoly.js +4 -0
  62. data/lib/generators/katapult/basics/templates/features/support/capybara_screenshot.rb +7 -0
  63. data/lib/generators/katapult/basics/templates/features/support/factory_bot.rb +1 -0
  64. data/lib/generators/katapult/basics/templates/features/support/paths.rb +7 -2
  65. data/lib/generators/katapult/basics/templates/features/support/rspec_doubles.rb +1 -0
  66. data/lib/generators/katapult/basics/templates/features/support/selectors.rb +3 -3
  67. data/lib/generators/katapult/basics/templates/features/support/selenium.rb +13 -0
  68. data/lib/generators/katapult/basics/templates/features/support/{env-custom.rb → spreewald.rb} +0 -0
  69. data/lib/generators/katapult/basics/templates/features/support/webpacker.rb +35 -0
  70. data/lib/generators/katapult/basics/templates/lib/ext/action_view/form_for_with_development_errors.rb +31 -31
  71. data/lib/generators/katapult/basics/templates/lib/ext/active_record/find_by_anything.rb +4 -3
  72. data/lib/generators/katapult/basics/templates/public/robots.txt +5 -0
  73. data/lib/generators/katapult/basics/templates/spec/assets/sample.pdf +0 -0
  74. data/lib/generators/katapult/basics/templates/spec/factories/factories.rb +1 -1
  75. data/lib/generators/katapult/basics/templates/spec/support/database_cleaner.rb +20 -0
  76. data/lib/generators/katapult/basics/templates/spec/support/factory_bot.rb +3 -0
  77. data/lib/generators/katapult/basics/templates/spec/support/fixture_file.rb +6 -0
  78. data/lib/generators/katapult/basics/templates/spec/support/postgresql_sequences.rb +15 -0
  79. data/lib/generators/katapult/basics/templates/spec/support/timecop.rb +3 -0
  80. data/lib/generators/katapult/clearance/clearance_generator.rb +14 -2
  81. data/lib/generators/katapult/clearance/templates/app/views/layouts/_current_user.html.haml +11 -0
  82. data/lib/generators/katapult/clearance/templates/app/views/passwords/create.html.haml +10 -4
  83. data/lib/generators/katapult/clearance/templates/app/views/passwords/edit.html.haml +12 -12
  84. data/lib/generators/katapult/clearance/templates/app/views/passwords/new.html.haml +14 -11
  85. data/lib/generators/katapult/clearance/templates/app/views/sessions/new.html.haml +16 -15
  86. data/lib/generators/katapult/clearance/templates/features/authentication.feature +3 -3
  87. data/lib/generators/katapult/cucumber_features/templates/feature.feature +1 -1
  88. data/lib/generators/katapult/model_specs/templates/model_spec.rb +3 -5
  89. data/lib/generators/katapult/navigation/navigation_generator.rb +7 -1
  90. data/lib/generators/katapult/navigation/templates/app/views/layouts/_navigation.html.haml +15 -0
  91. data/lib/generators/katapult/transform/transform_generator.rb +12 -17
  92. data/lib/generators/katapult/views/templates/_form.html.haml +48 -0
  93. data/lib/generators/katapult/views/templates/app/helpers/table_helper.rb +14 -0
  94. data/lib/generators/katapult/views/templates/app/webpack/assets/stylesheets/blocks/action_bar.sass +22 -0
  95. data/lib/generators/katapult/views/templates/app/webpack/assets/stylesheets/blocks/title.sass +11 -0
  96. data/lib/generators/katapult/views/templates/custom_action.html.haml +5 -0
  97. data/lib/generators/katapult/views/templates/edit.html.haml +4 -0
  98. data/lib/generators/katapult/views/templates/index.html.haml +26 -0
  99. data/lib/generators/katapult/{haml → views}/templates/new.html.haml +1 -1
  100. data/lib/generators/katapult/views/templates/show.html.haml +39 -0
  101. data/lib/generators/katapult/{haml/haml_generator.rb → views/views_generator.rb} +19 -25
  102. data/lib/generators/katapult/{w_u_i → web_ui}/templates/_route.rb +3 -3
  103. data/lib/generators/katapult/{w_u_i → web_ui}/templates/controller.rb +21 -23
  104. data/lib/generators/katapult/{w_u_i/w_u_i_generator.rb → web_ui/web_ui_generator.rb} +7 -12
  105. data/lib/katapult/action.rb +1 -1
  106. data/lib/katapult/application_model.rb +8 -8
  107. data/lib/katapult/binary_util.rb +48 -10
  108. data/lib/katapult/generator.rb +2 -10
  109. data/lib/katapult/generator_goodies.rb +23 -0
  110. data/lib/katapult/navigation.rb +10 -5
  111. data/lib/katapult/parser.rb +15 -8
  112. data/lib/katapult/version.rb +5 -1
  113. data/lib/katapult/{wui.rb → web_ui.rb} +19 -4
  114. data/lib/katapult.rb +0 -5
  115. data/script/console +5 -2
  116. data/script/kta +8 -0
  117. data/script/update +80 -0
  118. data/spec/action_spec.rb +0 -1
  119. data/spec/attribute_spec.rb +0 -1
  120. data/spec/element_spec.rb +0 -1
  121. data/spec/model_spec.rb +0 -1
  122. data/spec/parser_spec.rb +26 -0
  123. data/spec/util_spec.rb +0 -1
  124. data/spec/{wui_spec.rb → web_ui_spec.rb} +24 -12
  125. metadata +86 -124
  126. data/lib/generators/katapult/basics/templates/app/assets/stylesheets/application/blocks/_all.sass +0 -4
  127. data/lib/generators/katapult/basics/templates/app/assets/stylesheets/application/blocks/_items.sass +0 -11
  128. data/lib/generators/katapult/basics/templates/app/assets/stylesheets/application/blocks/_layout.sass +0 -26
  129. data/lib/generators/katapult/basics/templates/app/assets/stylesheets/application/blocks/_navigation.sass +0 -11
  130. data/lib/generators/katapult/basics/templates/app/assets/stylesheets/application/blocks/_tools.sass +0 -12
  131. data/lib/generators/katapult/basics/templates/app/assets/stylesheets/application.sass +0 -6
  132. data/lib/generators/katapult/basics/templates/config/spring.rb +0 -3
  133. data/lib/generators/katapult/basics/templates/features/support/factory_girl.rb +0 -1
  134. data/lib/generators/katapult/basics/templates/spec/support/factory_girl.rb +0 -3
  135. data/lib/generators/katapult/haml/templates/_form.html.haml +0 -38
  136. data/lib/generators/katapult/haml/templates/app/views/layouts/application.html.haml +0 -33
  137. data/lib/generators/katapult/haml/templates/custom_action.html.haml +0 -5
  138. data/lib/generators/katapult/haml/templates/edit.html.haml +0 -4
  139. data/lib/generators/katapult/haml/templates/index.html.haml +0 -29
  140. data/lib/generators/katapult/haml/templates/show.html.haml +0 -39
  141. data/lib/generators/katapult/install/install_generator.rb +0 -14
  142. data/lib/generators/katapult/install/templates/lib/katapult/application_model.rb +0 -20
  143. data/lib/generators/katapult/navigation/templates/app/models/navigation.rb +0 -12
@@ -6,8 +6,9 @@ module Katapult
6
6
  module Generators
7
7
  class ClearanceGenerator < Katapult::Generator
8
8
 
9
- desc 'Generate authentication with Clearance'
9
+ MENU_BAR = 'app/views/layouts/_menu_bar.html.haml'
10
10
 
11
+ desc 'Generate authentication with Clearance'
11
12
  check_class_collision
12
13
  source_root File.expand_path('../templates', __FILE__)
13
14
 
@@ -74,6 +75,17 @@ resources :users do
74
75
  ROUTES
75
76
  end
76
77
 
78
+ def add_current_user_to_layout
79
+ template 'app/views/layouts/_current_user.html.haml'
80
+ inject_into_file MENU_BAR, <<-CONTENT, after: /^\s+#navbar.*\n/
81
+ = render 'layouts/current_user' if signed_in?
82
+ CONTENT
83
+ end
84
+
85
+ def hide_navigation_unless_signed_in
86
+ gsub_file MENU_BAR, /(render.*navigation')/, '\1 if signed_in?'
87
+ end
88
+
77
89
  def add_sign_in_background_to_all_features
78
90
  Dir['features/*.feature'].each do |file|
79
91
  inject_into_file file, <<-CONTENT, after: /^Feature: .*$/
@@ -110,7 +122,7 @@ resources :users do
110
122
  end
111
123
 
112
124
  def add_user_factory
113
- inject_into_file 'spec/factories/factories.rb', <<-'CONTENT', after: 'FactoryGirl.define do'
125
+ inject_into_file 'spec/factories/factories.rb', <<-'CONTENT', after: 'FactoryBot.define do'
114
126
 
115
127
  factory :user do
116
128
  sequence(:email) { |i| "user-#{ i }@example.com" }
@@ -0,0 +1,11 @@
1
+ %ul.nav.navbar-nav.navbar-right
2
+ %li.dropdown
3
+ = link_to edit_user_path(current_user), data: { toggle: 'dropdown' } do
4
+ Hello,
5
+ = current_user
6
+ %span.caret
7
+
8
+ %ul.dropdown-menu
9
+ %li= link_to 'Edit profile', edit_user_path(current_user)
10
+ %li.divider
11
+ %li= link_to 'Sign out', sign_out_path, method: :delete, class: 'navbar-logout'
@@ -1,5 +1,11 @@
1
- %h1
2
- Password Reset Instructions Sent
1
+ .row
2
+ .col-md-4.col-md-offset-4
3
3
 
4
- %p
5
- We've sent you an email with instructions on how to reset your password.
4
+ %h1
5
+ Password Reset Instructions Sent
6
+
7
+ %p
8
+ We've sent you an email with instructions on how to reset your password.
9
+
10
+ %p
11
+ = link_to 'Back to sign-in form', sign_in_path, class: 'btn btn-primary'
@@ -1,16 +1,16 @@
1
- %h1
2
- Reset Password
1
+ .row
2
+ .col-md-4.col-md-offset-4
3
3
 
4
- %p
5
- Choose your new password:
4
+ %h1
5
+ Reset Password
6
6
 
7
- = form_for :password_reset,
8
- url: user_password_path(@user, token: @user.confirmation_token),
9
- html: { method: :put } do |form|
7
+ = form_for :password_reset,
8
+ url: user_password_path(@user, token: @user.confirmation_token),
9
+ html: { method: :put } do |form|
10
10
 
11
- .form-group
12
- = form.label :password
13
- = form.password_field :password, class: 'form-control',
14
- placeholder: 'New Password'
11
+ .form-group
12
+ = form.label :password
13
+ = form.password_field :password, class: 'form-control',
14
+ placeholder: 'New password'
15
15
 
16
- = form.submit 'Update Password', class: 'btn btn-primary'
16
+ = form.submit 'Update password', class: 'btn btn-primary'
@@ -1,14 +1,17 @@
1
- %h1
2
- Password Reset
1
+ .row
2
+ .col-md-4.col-md-offset-4
3
3
 
4
- %p
5
- Please enter your email address. We will send you instructions on how
6
- to reset your password.
4
+ %h1
5
+ Password Reset
7
6
 
8
- = form_for :password, url: passwords_path do |form|
9
- .form-group
10
- = form.label :email
11
- = form.email_field :email, class: 'form-control',
12
- placeholder: 'Email Address'
7
+ %p
8
+ Please enter your email address. We will send you instructions on how
9
+ to reset your password.
13
10
 
14
- = form.submit 'Request Instructions', class: 'btn btn-primary'
11
+ = form_for :password, url: passwords_path do |form|
12
+ .form-group
13
+ = form.label :email
14
+ = form.email_field :email, class: 'form-control',
15
+ placeholder: 'Email address'
16
+
17
+ = form.submit 'Request instructions', class: 'btn btn-primary'
@@ -1,19 +1,20 @@
1
- %h1
2
- Please sign in
1
+ .row
2
+ .col-md-4.col-md-offset-4
3
3
 
4
- = form_for :session, url: session_path do |form|
5
- .form-group
6
- = form.label :email
7
- = form.email_field :email, class: 'form-control',
8
- placeholder: 'Email Address', required: true, autofocus: true
4
+ %h1
5
+ Please sign in
9
6
 
10
- .form-group
11
- = form.label :password
12
- = form.password_field :password, class: 'form-control', required: true,
13
- placeholder: 'Password'
7
+ = form_for :session, url: session_path do |form|
8
+ .form-group
9
+ = form.label :email
10
+ = form.email_field :email, class: 'form-control',
11
+ placeholder: 'Email Address', required: true, autofocus: true
14
12
 
15
- %p
16
- = form.submit 'Sign in', class: 'btn btn-primary'
13
+ .form-group
14
+ = form.label :password
15
+ = form.password_field :password, class: 'form-control', required: true,
16
+ placeholder: 'Password'
17
17
 
18
- %p
19
- = link_to 'Forgot password', new_password_path, class: 'text-muted'
18
+ %p
19
+ = form.submit 'Sign in', class: 'btn btn-primary'
20
+ = link_to 'Forgot password', new_password_path, class: 'btn btn-link'
@@ -51,7 +51,7 @@ Feature: Everything about user authentication
51
51
  And I sign in as the user above
52
52
 
53
53
  When I go to the homepage
54
- And I follow "henry@example.com" within the current user
54
+ And I follow "henry@example.com" within the navbar
55
55
  Then I should be on the form for the user above
56
56
 
57
57
  When I fill in "Password" with "new-password"
@@ -74,7 +74,7 @@ Feature: Everything about user authentication
74
74
  And I should see "Password Reset"
75
75
 
76
76
  When I fill in "Email" with "henry@example.com"
77
- And I press "Request Instructions"
77
+ And I press "Request instructions"
78
78
  Then an email should have been sent with:
79
79
  """
80
80
  From: system@example.com
@@ -89,6 +89,6 @@ Feature: Everything about user authentication
89
89
  And I should see "Reset Password"
90
90
 
91
91
  When I fill in "Choose password" with "new-password"
92
- And I press "Update Password"
92
+ And I press "Update password"
93
93
  Then I should see "Password successfully changed" within the flash
94
94
  And I should be on the homepage
@@ -59,5 +59,5 @@ Feature: <%= model.name(:humans).titleize %>
59
59
 
60
60
  When I follow "Destroy <%= model.label_attr.test_value %>"
61
61
  Then I should be on the list of <%= model.name(:variables) %>
62
- But I should not see "<%= model.label_attr.test_value %>"
62
+ But I should not see "<%= model.label_attr.test_value %>"
63
63
  <% end -%>
@@ -1,17 +1,15 @@
1
- require 'rails_helper'
2
-
3
1
  describe <%= model.name :class %> do
4
2
 
5
3
  describe '#to_s' do
6
4
  <%- if model.label_attr -%>
7
5
  it 'returns the #<%= model.label_attr.name %> attribute' do
8
6
  subject.<%= model.label_attr.name %> = <%= model.label_attr.test_value.inspect %>
9
- expect(subject.to_s).to eql(<%= model.label_attr.test_value.to_s.inspect %>)
7
+ expect(subject.to_s).to eq(<%= model.label_attr.test_value.to_s.inspect %>)
10
8
  end
11
9
  <%- else -%>
12
10
  it 'returns its class name with its id' do
13
11
  subject.id = 17
14
- expect(subject.to_s).to eql("<%= model.name %>#17")
12
+ expect(subject.to_s).to eq("<%= model.name %>#17")
15
13
  end
16
14
  <%- end -%>
17
15
  end
@@ -25,7 +23,7 @@ describe <%= model.name :class %> do
25
23
  <%- unless attr.default.nil? -%>
26
24
 
27
25
  it 'has a default' do
28
- expect( subject.<%= attr.name %> ).to eql(<%= attr.default.inspect %>)
26
+ expect(subject.<%= attr.name %>).to eq(<%= attr.default.inspect %>)
29
27
  end
30
28
  <%- end -%>
31
29
  end
@@ -6,12 +6,18 @@ module Katapult
6
6
  module Generators
7
7
  class NavigationGenerator < Katapult::Generator
8
8
 
9
+ MENU_BAR = 'app/views/layouts/_menu_bar.html.haml'
10
+
9
11
  desc 'Generate the navigation'
10
12
  source_root File.expand_path('../templates', __FILE__)
11
13
 
12
14
 
13
15
  def create_navigation
14
- template 'app/models/navigation.rb'
16
+ template 'app/views/layouts/_navigation.html.haml'
17
+
18
+ inject_into_file MENU_BAR, <<-CONTENT, after: /^\s+#navbar.*\n/
19
+ = render 'layouts/navigation'
20
+ CONTENT
15
21
  end
16
22
 
17
23
  private
@@ -0,0 +1,15 @@
1
+ %ul.nav.navbar-nav
2
+ <% navigation.links.each do |label, path| -%>
3
+ %li(up-expand)
4
+ = content_link_to <%= label.titleize.inspect %>, <%= path %>
5
+ <% end -%>
6
+
7
+ %li.dropdown
8
+ = link_to '#', data: { toggle: 'dropdown' } do
9
+ Dropdown example
10
+ %span.caret
11
+
12
+ %ul.dropdown-menu
13
+ %li= link_to 'One', '#'
14
+ %li.divider
15
+ %li= link_to 'Two', '#'
@@ -6,9 +6,12 @@
6
6
  # 2) render the parsed model into code
7
7
 
8
8
  require 'katapult/parser'
9
+ require 'katapult/generator_goodies'
9
10
 
10
11
  module Katapult
11
12
  class TransformGenerator < Rails::Generators::Base
13
+ include Katapult::GeneratorGoodies
14
+
12
15
  desc 'Transform the katapult application model'
13
16
 
14
17
  argument :path, required: true, type: :string,
@@ -16,34 +19,26 @@ module Katapult
16
19
 
17
20
  def transform_application_model
18
21
  say_status :parse, path
19
- @app_model = Katapult::Parser.new.parse(path)
22
+ application_model = File.read(path)
23
+ @app_model = Katapult::Parser.new.parse(application_model, path)
20
24
 
21
- say_status :render, "into #{application_name}"
25
+ say_status :render, "into #{app_name}"
22
26
  @app_model.render
23
27
  end
24
28
 
25
29
  def write_root_route
26
30
  unless File.read('config/routes.rb').include? ' root'
27
- root_wui = @app_model.wuis.find { |w| w.find_action :index }
28
- route "root '#{ root_wui.model_name(:variables) }#index'" if root_wui
31
+ root_web_ui = @app_model.web_uis.find { |w| w.find_action :index }
32
+ route "root '#{ root_web_ui.model_name(:variables) }#index'" if root_web_ui
29
33
  end
30
34
  end
31
35
 
32
36
  def remigrate_all_databases
33
- run 'spring stop' # parallel_tests does not work together with Spring
34
- run 'rake db:drop:all db:create:all db:migrate parallel:create parallel:prepare'
35
- end
36
-
37
- private
37
+ return if ENV['SKIP_MIGRATIONS'] # Used to speed up tests
38
38
 
39
- def application_name
40
- File.basename(Dir.pwd)
41
- end
42
-
43
- def run(*)
44
- Bundler.with_clean_env do
45
- super
46
- end
39
+ run 'rake db:drop db:create db:migrate'
40
+ # See comment to Katapult::BasicsGenerator#create_databases
41
+ run 'unset RAILS_ENV; rake parallel:drop parallel:create parallel:prepare'
47
42
  end
48
43
 
49
44
  end
@@ -0,0 +1,48 @@
1
+ <%- object = model_name(:ivar) -%>
2
+ = form_for <%= object %> do |form|
3
+
4
+ <% web_ui.model.editable_attrs.each do |attribute| -%>
5
+ .form-group
6
+ = form.label <%= attribute.name(:symbol) %>
7
+ <%- if attribute.assignable_values -%>
8
+ = form.select <%= attribute.name(:symbol) %>, form.object.assignable_<%= attribute.name(:variables) %>
9
+ <%- else -%>
10
+ <%- case attribute.type -%>
11
+ <%- when :string -%>
12
+ = form.text_field <%= attribute.name(:symbol) %>, class: 'form-control'
13
+ <%- when :email -%>
14
+ = form.email_field <%= attribute.name(:symbol) %>, class: 'form-control'
15
+ <%- when :password -%>
16
+ = form.password_field <%= attribute.name(:symbol) %>, class: 'form-control',
17
+ autocomplete: 'new-password'
18
+ <%- when :url -%>
19
+ = form.url_field <%= attribute.name(:symbol) %>, class: 'form-control'
20
+ <%- when :integer -%>
21
+ = form.number_field <%= attribute.name(:symbol) %>, class: 'form-control'
22
+ <%- when :money -%>
23
+ .input-group
24
+ = form.number_field <%= attribute.name(:symbol) %>, class: 'form-control'
25
+ .input-group-addon
26
+
27
+ <%- when :text -%>
28
+ = form.text_area <%= attribute.name(:symbol) %>, rows: 5, class: 'form-control'
29
+ <%- when :flag -%>
30
+ .checkbox
31
+ = form.label <%= attribute.name(:symbol) %> do
32
+ = form.check_box <%= attribute.name(:symbol) %>
33
+ <%- when :datetime -%>
34
+ = form.date_field <%= attribute.name(:symbol) %>, class: 'form-control'
35
+ <%- end -%>
36
+ <%- end -%>
37
+ <% end -%>
38
+
39
+ .action-bar
40
+ - cancel_path = <%= object %>.new_record? ? <%= web_ui.path(:index) %> : <%= web_ui.path(:show, object) %>
41
+
42
+ .pull-right
43
+ - if <%= object %>.persisted?
44
+ = link_to "Destroy <%= model_name(:human) %>", <%= web_ui.path(:destroy, object) %>, method: :delete,
45
+ class: 'btn btn-danger', data: { confirm: 'Really destroy?' }
46
+
47
+ = form.submit 'Save', class: 'btn btn-primary'
48
+ = link_to 'Cancel', cancel_path, class: 'btn btn-link'
@@ -0,0 +1,14 @@
1
+ module TableHelper
2
+
3
+ def table(*headers, &block)
4
+ thead = content_tag(:thead) do
5
+ content_tag(:tr) do
6
+ headers.map{ |h| content_tag :th, h }.xss_aware_join
7
+ end
8
+ end
9
+ rest = capture(&block)
10
+
11
+ content_tag :table, thead + rest, class: 'table table-hover'
12
+ end
13
+
14
+ end
@@ -0,0 +1,22 @@
1
+ @import ../environment
2
+
3
+ .action-bar
4
+ margin-top: $space-md
5
+ border-top: 1px solid $panel-default-border
6
+ padding-top: $space-xs
7
+
8
+ &.-main
9
+ float: right
10
+
11
+ margin-top: 3px
12
+ border: none
13
+ padding: 0
14
+
15
+ +within-modal
16
+ margin: 30px -40px -30px
17
+ padding: 15px 40px
18
+
19
+ background: $panel-footer-bg
20
+ border-bottom-left-radius: $border-radius-base
21
+ border-bottom-right-radius: $border-radius-base
22
+
@@ -0,0 +1,11 @@
1
+ @import ../environment
2
+
3
+ h1.title
4
+ margin: $space-lg 0 $space-sm -2px
5
+
6
+ +within-modal
7
+ margin-top: 3px
8
+
9
+ h2.title
10
+ margin: $space-sm 0
11
+
@@ -0,0 +1,5 @@
1
+ .action-bar
2
+ = link_to 'All <%= model_name(:humans) %>', <%= web_ui.path(:index) %>, class: 'btn btn-default'
3
+
4
+ %h1.title
5
+ <%= @action.name.humanize.titleize %>
@@ -0,0 +1,4 @@
1
+ %h1.title
2
+ = <%= model_name(:ivar) %>
3
+
4
+ = render 'form'
@@ -0,0 +1,26 @@
1
+ .action-bar.-main.btn-group
2
+ = link_to 'Add <%= model_name(:human) %>', <%= web_ui.path(:new) %>, class: 'btn btn-default'
3
+ <% web_ui.custom_actions.select(&:collection?).each do |action| -%>
4
+ = link_to '<%= action.name.humanize.titleize %>', <%= web_ui.path(action) %>, class: 'btn btn-default'
5
+ <% end -%>
6
+
7
+ %h1.title
8
+ <%= model_name(:humans).capitalize %>
9
+
10
+ - if <%= model_name(:ivars) %>.any?
11
+ <%- object = model_name(:variable) -%>
12
+
13
+ = table '<%= web_ui.model.label_attr.name(:human).titleize %>', 'Actions' do
14
+ - <%= model_name(:ivars) %>.each do |<%= object %>|
15
+ %tr(up-expand)
16
+ %td(width='40%')
17
+ = link_to <%= object %>, <%= object %>
18
+ %td
19
+ = link_to 'Edit', <%= web_ui.path(:edit, object) %>
20
+ = link_to 'Destroy', <%= web_ui.path(:destroy, object) %>, method: :delete,
21
+ class: 'text-danger',
22
+ data: { confirm: 'Really destroy?' }, title: "Destroy #{<%= object %>}"
23
+
24
+ - else
25
+ %p.help-block
26
+ No <%= model_name(:humans) %> found.
@@ -1,4 +1,4 @@
1
- %h1
1
+ %h1.title
2
2
  Add <%= model_name(:human) %>
3
3
 
4
4
  = render 'form'
@@ -0,0 +1,39 @@
1
+ <%- object = model_name(:ivar) -%>
2
+ .action-bar.-main.btn-group
3
+ = link_to 'All <%= model_name(:humans) %>', <%= web_ui.path(:index) %>, class: 'btn btn-default'
4
+ = link_to 'Edit', <%= web_ui.path(:edit, object) %>, class: 'btn btn-default'
5
+ <% web_ui.custom_actions.select(&:member?).each do |action| -%>
6
+ = link_to '<%= action.name(:human).titleize %>', <%= web_ui.path(action, object) %>, class: 'btn btn-default'<%=
7
+ ", method: :#{action.method}" unless action.get?
8
+ %>
9
+ <% end -%>
10
+
11
+ %h1.title
12
+ = <%= model_name(:ivar) %>
13
+
14
+ %dl
15
+ <% web_ui.model.renderable_attrs.each do |attribute| -%>
16
+ <%- model_attribute = "#{object}.#{attribute.name}" -%>
17
+ %dt
18
+ = <%= model_name(:class) %>.human_attribute_name(:<%= attribute.name %>)
19
+ %dd
20
+ <%- case attribute.type -%>
21
+ <%- when :string -%>
22
+ = <%= model_attribute %>
23
+ <%- when :email -%>
24
+ = mail_to <%= model_attribute %>, nil
25
+ <%- when :url -%>
26
+ = link_to <%= model_attribute %>, <%= model_attribute %>
27
+ <%- when :integer -%>
28
+ = <%= model_attribute %>
29
+ <%- when :money -%>
30
+ = <%= model_attribute %>
31
+
32
+ <%- when :text -%>
33
+ = simple_format(<%= model_attribute %>)
34
+ <%- when :flag -%>
35
+ = <%= model_attribute %> ? 'Yes' : 'No'
36
+ <%- when :datetime -%>
37
+ = l(<%= model_attribute %>.to_date) if <%= model_attribute %>
38
+ <%- end -%>
39
+ <%- end -%>
@@ -1,28 +1,30 @@
1
- # Generate views for a WUI.
1
+ # Generate views for a WebUI
2
2
 
3
3
  require 'katapult/generator'
4
4
  require 'generators/katapult/cucumber_features/cucumber_features_generator'
5
5
 
6
6
  module Katapult
7
7
  module Generators
8
- class HamlGenerator < Katapult::Generator
8
+ class ViewsGenerator < Katapult::Generator
9
9
 
10
10
  desc 'Generate HAML views'
11
11
  source_root File.expand_path('../templates', __FILE__)
12
12
 
13
13
 
14
- def install_application_layout
15
- remove_file 'app/views/layouts/application.html.erb'
16
- template 'app/views/layouts/application.html.haml'
17
- template 'app/views/layouts/_flashes.html.haml'
18
- end
19
-
20
14
  def create_views_directory
21
15
  FileUtils.mkdir_p views_path
22
16
  end
23
17
 
18
+ def install_helpers
19
+ directory 'app/helpers'
20
+ end
21
+
22
+ def install_styles
23
+ directory 'app/webpack/assets/stylesheets/blocks'
24
+ end
25
+
24
26
  def create_rails_standard_action_views
25
- actions.select{ |a| a.get? && WUI::RAILS_ACTIONS.include?(a.name) }.each do |action|
27
+ actions.select{ |a| a.get? && WebUI::RAILS_ACTIONS.include?(a.name) }.each do |action|
26
28
  file_name = "#{action.name}.html.haml"
27
29
 
28
30
  create_view file_name, File.join(views_path, file_name)
@@ -40,54 +42,46 @@ module Katapult
40
42
  end
41
43
 
42
44
  def create_views_for_custom_actions
43
- wui.custom_actions.select(&:get?).each do |action|
45
+ web_ui.custom_actions.select(&:get?).each do |action|
44
46
  @action = action # Make the action object accessible in templates
45
47
  create_view 'custom_action.html.haml', File.join(views_path, "#{action.name}.html.haml")
46
48
  end
47
49
  end
48
50
 
49
51
  def generate_integration_tests
50
- if wui.model.present?
51
- Generators::CucumberFeaturesGenerator.new(wui.model).invoke_all
52
+ if web_ui.model.present?
53
+ Generators::CucumberFeaturesGenerator.new(web_ui.model).invoke_all
52
54
  end
53
55
  end
54
56
 
55
57
  no_tasks do
56
58
  def model_name(kind = nil)
57
- wui.model_name(kind)
59
+ web_ui.model_name(kind)
58
60
  end
59
61
 
60
62
  def views_path
61
63
  File.join('app', 'views', model_name(:variables))
62
64
  end
63
-
64
- def navigation
65
- wui.application_model.navigation
66
- end
67
-
68
- def authentication
69
- wui.application_model.authentication
70
- end
71
65
  end
72
66
 
73
67
  private
74
68
 
75
- # Rails views depend heavily on models. If the WUI has no model, do not
69
+ # Rails views depend heavily on models. If the WebUI has no model, do not
76
70
  # use the templates but create empty files instead.
77
71
  def create_view(template, destination)
78
- if wui.model
72
+ if web_ui.model
79
73
  template template, destination
80
74
  else
81
75
  create_file destination
82
76
  end
83
77
  end
84
78
 
85
- def wui
79
+ def web_ui
86
80
  @element
87
81
  end
88
82
 
89
83
  def actions
90
- wui.actions
84
+ web_ui.actions
91
85
  end
92
86
 
93
87
  end
@@ -1,12 +1,12 @@
1
- % rails_actions = wui.actions - wui.custom_actions
1
+ % rails_actions = web_ui.actions - web_ui.custom_actions
2
2
  resources <%= model_name(:symbols) %>, only: <%= rails_actions.map(&:name).map(&:to_sym) %> do
3
3
  member do
4
- % wui.custom_actions.select(&:member?).each do |action|
4
+ % web_ui.custom_actions.select(&:member?).each do |action|
5
5
  <%= action.method %> '<%= action.name %>'
6
6
  % end
7
7
  end
8
8
  collection do
9
- % wui.custom_actions.select(&:collection?).each do |action|
9
+ % web_ui.custom_actions.select(&:collection?).each do |action|
10
10
  <%= action.method %> '<%= action.name %>'
11
11
  % end
12
12
  end