wobapphelpers 3.1.0

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 (79) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +155 -0
  4. data/Rakefile +30 -0
  5. data/app/assets/stylesheets/wobapphelpers/breadcrumbs.scss +13 -0
  6. data/config/locales/de.yml +9 -0
  7. data/config/locales/en.yml +9 -0
  8. data/lib/generators/templates/erb/scaffold/_form.html.erb +26 -0
  9. data/lib/generators/templates/erb/scaffold/edit.html.erb +1 -0
  10. data/lib/generators/templates/erb/scaffold/index.html.erb +32 -0
  11. data/lib/generators/templates/erb/scaffold/new.html.erb +1 -0
  12. data/lib/generators/templates/erb/scaffold/show.html.erb +15 -0
  13. data/lib/generators/templates/initializers/wobapphelpers.rb +18 -0
  14. data/lib/generators/templates/layouts/application.html.erb +44 -0
  15. data/lib/generators/templates/rails/scaffold_controller/controller.rb +66 -0
  16. data/lib/generators/wobapphelpers/install_generator.rb +24 -0
  17. data/lib/generators/wobapphelpers/scaffold_templates_generator.rb +20 -0
  18. data/lib/tasks/wobapphelpers_tasks.rake +4 -0
  19. data/lib/wobapphelpers.rb +37 -0
  20. data/lib/wobapphelpers/breadcrumbs.rb +16 -0
  21. data/lib/wobapphelpers/breadcrumbs/action_controller.rb +57 -0
  22. data/lib/wobapphelpers/breadcrumbs/breadcrumbs_helper.rb +26 -0
  23. data/lib/wobapphelpers/helpers.rb +12 -0
  24. data/lib/wobapphelpers/helpers/action_view_helper.rb +170 -0
  25. data/lib/wobapphelpers/helpers/icon_helper.rb +39 -0
  26. data/lib/wobapphelpers/rails.rb +4 -0
  27. data/lib/wobapphelpers/responders.rb +13 -0
  28. data/lib/wobapphelpers/responders/locales/de.yml +12 -0
  29. data/lib/wobapphelpers/responders/locales/en.yml +12 -0
  30. data/lib/wobapphelpers/version.rb +4 -0
  31. data/test/breadcrumbs/action_controller_test.rb +44 -0
  32. data/test/breadcrumbs/breadcrumb_helper_test.rb +35 -0
  33. data/test/dummy/app/controllers/application_controller.rb +19 -0
  34. data/test/dummy/app/controllers/blogs_controller.rb +55 -0
  35. data/test/dummy/app/controllers/home_controller.rb +7 -0
  36. data/test/dummy/app/controllers/posts_controller.rb +58 -0
  37. data/test/dummy/app/helpers/application_helper.rb +3 -0
  38. data/test/dummy/app/helpers/blogs_helper.rb +2 -0
  39. data/test/dummy/app/helpers/posts_helper.rb +2 -0
  40. data/test/dummy/app/models/blog.rb +2 -0
  41. data/test/dummy/app/models/post.rb +2 -0
  42. data/test/dummy/config/application.rb +31 -0
  43. data/test/dummy/config/boot.rb +5 -0
  44. data/test/dummy/config/environment.rb +5 -0
  45. data/test/dummy/config/environments/development.rb +37 -0
  46. data/test/dummy/config/environments/production.rb +83 -0
  47. data/test/dummy/config/environments/test.rb +45 -0
  48. data/test/dummy/config/initializers/assets.rb +1 -0
  49. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  50. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  51. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  52. data/test/dummy/config/initializers/inflections.rb +16 -0
  53. data/test/dummy/config/initializers/mime_types.rb +4 -0
  54. data/test/dummy/config/initializers/session_store.rb +3 -0
  55. data/test/dummy/config/initializers/simple_form.rb +161 -0
  56. data/test/dummy/config/initializers/simple_form_bootstrap.rb +107 -0
  57. data/test/dummy/config/initializers/wobapphelpers.rb +9 -0
  58. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  59. data/test/dummy/config/routes.rb +61 -0
  60. data/test/dummy/db/migrate/20140420155942_create_posts.rb +12 -0
  61. data/test/dummy/db/migrate/20140516164637_create_blogs.rb +12 -0
  62. data/test/dummy/db/schema.rb +33 -0
  63. data/test/dummy/lib/templates/rails/scaffold_controller/controller.rb +65 -0
  64. data/test/generators/install_generator_test.rb +29 -0
  65. data/test/generators/scaffold_templates_generator_test.rb +16 -0
  66. data/test/helpers/action_view_helper_test.rb +41 -0
  67. data/test/helpers/active_class_helper_test.rb +9 -0
  68. data/test/helpers/can_view_helper_test.rb +172 -0
  69. data/test/helpers/flash_helper_test.rb +11 -0
  70. data/test/helpers/form_legend_test.rb +29 -0
  71. data/test/helpers/icon_helper_test.rb +21 -0
  72. data/test/helpers/show_edit_delete_link_helper_test.rb +45 -0
  73. data/test/integration/helper_delivery_test.rb +28 -0
  74. data/test/responders/flash_test.rb +23 -0
  75. data/test/test_helper.rb +42 -0
  76. data/test/tmp/lib/templates/rails/scaffold_controller/controller.rb +66 -0
  77. data/test/translate_test.rb +10 -0
  78. data/test/wobapphelpers_test.rb +20 -0
  79. metadata +371 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad34edf1a5b43d0676b3d41201de77495d6d262b
4
+ data.tar.gz: 98a713a4a5e0f5819c4eca403ca7f945047a89e4
5
+ SHA512:
6
+ metadata.gz: b7c1b1268b553bcbeaf501060e45807d01e09969b6eae1633eea4191c8c8adc85d28113fa3c695c79b9c9f9217773b0487ae32d018e6836dcd7dd241ed275f52
7
+ data.tar.gz: 790f9781a9172aca798029c331e598d127bc48b562964fcc99b83888871addfc7155ced9317f19410089f2a9a9a2f2ecca17f3c3bae5e6e24e41a02f4cf8ab85
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2018 Wolfgang Barth
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,155 @@
1
+ wobapphelpers
2
+ =============
3
+
4
+ Rails helpers and more shared between common wob rails applications. Depends on twitter bootstrap.
5
+
6
+ This is the ''master'' branch, for use with rails 5.1.
7
+
8
+ Requirements
9
+ ------------
10
+
11
+ | branch | rails | ruby | bootstrap | icons |
12
+ |------------|-------|--------|-----------|-------------|
13
+ | master | 5.1 | >= 2.3 | v4 | fontawesome |
14
+ | 2-0-stable | 5.0 | >= 2.2 | v3 | glyphicons |
15
+ | 1-0-stable | 4.2 | >= 2.0 | v3 | glyphicons |
16
+
17
+ * simple_form >= 3.3
18
+
19
+ Installation
20
+ ------------
21
+
22
+ gem 'wobapphelpers', github: 'swobspace/wobapphelpers', branch: "2-0-stable"
23
+ gem 'wobapphelpers', github: 'swobspace/wobapphelpers', branch: "1-0-stable"
24
+ gem 'wobapphelpers', github: 'swobspace/wobapphelpers', branch: "master"
25
+
26
+ Generators
27
+ ----------
28
+
29
+ wobapphelpers comes with some generators to install templates and so on:
30
+
31
+ * rails g wobapphelpers:install : installs some locales
32
+ * rails g wobapphelpers:scaffold_templates : installs scaffold erb and templates
33
+ and a controller template using simple_form and bootstrap, responders and the
34
+ famous respond_with method.
35
+
36
+ Usage
37
+ -----
38
+
39
+ ### Helpers
40
+
41
+ Helpers to ease use of glyphicon icons, predefined action links (i.e. edit_link),
42
+ show_flash, and more ...
43
+
44
+ # myapp/app/helpers/application_helper.rb:
45
+ module ApplicationHelper
46
+ include Wobapphelpers::Helpers::All
47
+ ...
48
+ #or use specific modules
49
+ include Wobapphelpers::Helpers::IconHelper
50
+ include Wobapphelpers::Helpers::ActionViewHelper
51
+ ...
52
+ end
53
+
54
+ ### Responders
55
+
56
+ Predefined settings for FlashResponder in gem 'responders'
57
+ (https://github.com/plataformatec/responders) including german locales.
58
+
59
+ # myapp/app/controllers/application_controller.rb
60
+ class ApplicationController < ActionController::Base
61
+ self.responder = Wobapphelpers::Responders
62
+ ...
63
+ end
64
+
65
+ ### Breadcrumbs
66
+
67
+ Build breadcrumbs in the sense of backtrace, not of deepness. An example for
68
+ classical breadcrumbs is
69
+
70
+ Home >> Posts >> posts#show
71
+
72
+ Wobapphelpers::Breadcrumbs store a the last 6 urls like this:
73
+
74
+ Home >> Posts >> Post(1) >> Others >> Posts
75
+
76
+ A breadcrumb will only be
77
+ added if the url differs from the last breadcrumb on the stack.
78
+ Wobapphelper::Breadcrumbs should be use in normal display actions like index
79
+ or show, but not in actions which are redirecting to others (not in :create,
80
+ :update) and best not to use in form actions like :edit and :new. The latter
81
+ is a question of user experience, not a technical question. The back_link
82
+ from Wobapphelpers::Helpers::ActionViewHelper uses breadcrumbs, if available,
83
+ so it would be better to build your own back link if you set breadcrumbs for
84
+ :new and :edit.
85
+
86
+ #### Breadcrumbs for #index
87
+
88
+ Setting breadcrumbs for index can be done in ApplicationController:
89
+
90
+ # myapp/app/controllers/application_controller.rb
91
+ class ApplicationController < ActionController::Base
92
+ include Wobapphelpers::Breadcrumbs
93
+ before_filter :add_breadcrumb_index, only: [:index]
94
+ ...
95
+ end
96
+
97
+ #### Breadcrumbs for #show
98
+
99
+ Breadcrumbs for @post must be set after retrieving the object from database.
100
+ Pay attention to the correct order of before_actions:
101
+
102
+ # myapp/app/controllers/posts_controller.rb
103
+ class PostsController < ApplicationController
104
+ before_action :set_post, only: [:show, :edit, :update, :destroy]
105
+ before_action :add_breadcrumb_show, only: [:show]
106
+ ....
107
+
108
+ private
109
+
110
+ def set set_post
111
+ @post = Post.find(params[:id])
112
+ end
113
+ end
114
+
115
+ #### Generic Functions
116
+
117
+ # add a breadcrumb manually
118
+ add_breadcrumb(name, url)
119
+
120
+ # get the last breadcrumb from stack
121
+ last_breadcrumb_url
122
+
123
+ #### Styling breadcrumbs
124
+
125
+ Use builtin styling:
126
+
127
+ /* application.css
128
+ *= require wobapphelpers/breadcrumbs
129
+ /* ...
130
+
131
+ or build your own stuff. :render_breadcrumbs gives you
132
+ a div#breadcrumbs tag.
133
+
134
+
135
+ For :add_breadcrumb_show the variable must be named after your Model. For
136
+ other variable names you have to use :add_breadcrumbs_for, i.e.
137
+
138
+ # myapp/app/controllers/posts_controller.rb
139
+ class PostsController < ApplicationController
140
+ ...
141
+ def show
142
+ @other = Post.find(params[:id])
143
+ add_breadcrumbs_for(@other)
144
+ end
145
+ ...
146
+ end
147
+
148
+
149
+ Licence
150
+ -------
151
+
152
+ Wobapphelpers Copyright (C) 2014-2018 Wolfgang Barth
153
+
154
+ MIT License, see [LICENSE](LICENSE)
155
+
data/Rakefile ADDED
@@ -0,0 +1,30 @@
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 = 'Wobapphelpers'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ Bundler::GemHelper.install_tasks
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'lib'
23
+ t.libs << 'test'
24
+ t.pattern = 'test/**/*_test.rb'
25
+ t.verbose = false
26
+ t.warning = false
27
+ end
28
+
29
+
30
+ task default: :test
@@ -0,0 +1,13 @@
1
+
2
+ // --- breadcrumbs
3
+ #breadcrumbs {
4
+ color: #999;
5
+ padding: .5em 0 .5em 0;
6
+ a {
7
+ color: #999;
8
+ text-decoration: none;
9
+ &:hover { color: #111; }
10
+ &:hover { color: #111; }
11
+ }
12
+ }
13
+
@@ -0,0 +1,9 @@
1
+ de:
2
+ wobapphelpers:
3
+ helpers:
4
+ back: "Zurück"
5
+ cancel: "Abbrechen"
6
+ controller:
7
+ new: "%{name} erstellen"
8
+ edit: "%{name} bearbeiten"
9
+ update: "%{name} bearbeiten"
@@ -0,0 +1,9 @@
1
+ en:
2
+ wobapphelpers:
3
+ helpers:
4
+ back: Back
5
+ cancel: Cancel
6
+ controller:
7
+ new: "create %{name}"
8
+ edit: "update %{name}"
9
+ update: "update %{name}"
@@ -0,0 +1,26 @@
1
+ <%%= simple_form_for(@<%= singular_table_name %>,
2
+ html: { class: 'form-horizontal well' },
3
+ wrapper: :horizontal_form,
4
+ wrapper_mappings: {
5
+ check_boxes: :horizontal_radio_and_checkboxes,
6
+ radio_buttons: :horizontal_radio_and_checkboxes,
7
+ file: :horizontal_file_input,
8
+ boolean: :horizontal_boolean
9
+ }) do |f| %>
10
+
11
+ <fieldset>
12
+ <%%= form_legend %>
13
+
14
+ <div class="form-inputs">
15
+ <%- attributes.each do |attribute| -%>
16
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %><% (attribute.field_type == :date_select) ? ', as: :string' : '' %>
17
+ %>
18
+ <%- end -%>
19
+ </div>
20
+
21
+ <div class="col-sm-9 col-sm-offset-3">
22
+ <%%= f.button :submit, class: 'btn btn-primary' %>
23
+ <%%= cancel_button %>
24
+ </div>
25
+ </fieldset>
26
+ <%% end %>
@@ -0,0 +1 @@
1
+ <%%= render 'form' %>
@@ -0,0 +1,32 @@
1
+ <h1><%%= t('controller.<%= plural_table_name %>') %></h1>
2
+
3
+ <table id="dataTable" class="table table-bordered table-striped dataTable">
4
+ <thead>
5
+ <tr>
6
+ <% attributes.each do |attribute| -%>
7
+ <th><%%= t('attributes.<%= attribute.name %>') %></th>
8
+ <% end -%>
9
+ <th></th>
10
+ </tr>
11
+ </thead>
12
+ <tbody>
13
+
14
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
15
+ <%%= content_tag_for(:tr, <%= singular_table_name %>) do %>
16
+ <% attributes.each do |attribute| -%>
17
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
18
+ <% end -%>
19
+ <td class="nowrap">
20
+ <%%= show_link <%= singular_table_name %> %>
21
+ <%%= edit_link <%= singular_table_name %> %>
22
+ <%%= delete_link <%= singular_table_name %> %>
23
+ </td>
24
+ <%% end %>
25
+ <%% end %>
26
+ </tbody>
27
+ </table>
28
+
29
+ <br />
30
+
31
+ <%%= back_link %>
32
+ <%%= new_link <%= class_name %> %>
@@ -0,0 +1 @@
1
+ <%%= render 'form' %>
@@ -0,0 +1,15 @@
1
+ <table class="table table-bordered table-hover autowidth">
2
+ <% attributes.each do |attribute| %>
3
+ <tr>
4
+ <th><%%= t('attributes.<%= attribute.name %>')%>:</th>
5
+ <td><%%= @<%= singular_table_name %>.<%= attribute.name %> %></td>
6
+ </tr>
7
+ <% end -%>
8
+ </table>
9
+
10
+ <div role="toolbar">
11
+ <%%= back_link %>
12
+ <%%= edit_link(@<%= singular_table_name %>) %>
13
+ <%%= delete_link(@<%= singular_table_name %>) %>
14
+ <%%= new_link <%= class_name %> %>
15
+ </div>
@@ -0,0 +1,18 @@
1
+ Wobapphelpers.setup do |config|
2
+ #
3
+ # exclude some controllers from breadcrumbs
4
+ # the given string must match controller.controller_name
5
+ #
6
+ # example:
7
+ # config.breadcrumb_controller_blacklist = ["user_sessions"]
8
+ # default:
9
+ # config.breadcrumb_controller_blacklist = []
10
+ #
11
+ # show action links only if has ability to execute the action
12
+ # * :none : always present action links
13
+ # * :cancan1 : for cancancan '~>1.7.0' or cancan '~>1.6.0'
14
+ # * :cancan2 : for cancan '~>2.0.0', untested
15
+ #
16
+ # default:
17
+ # config.cancan = :none
18
+ end
@@ -0,0 +1,44 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <title>Dummy App</title>
8
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
9
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
10
+ <%= csrf_meta_tags %>
11
+ </head>
12
+ <body>
13
+ <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
14
+ <div class="container">
15
+ <div class="navbar-header">
16
+ <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
17
+ <span class="sr-only">Toggle navigation</span>
18
+ <span class="icon-bar"></span>
19
+ <span class="icon-bar"></span>
20
+ <span class="icon-bar"></span>
21
+ </button>
22
+ <a class="navbar-brand" href="<%= root_path if defined?(root_path)%>#">Dummy</a>
23
+ </div>
24
+ <div class="collapse navbar-collapse">
25
+ <ul class="nav navbar-nav">
26
+ <li class="active"><a href="/home">Home</a></li>
27
+ </ul>
28
+ </div><!--/.nav-collapse -->
29
+ </div>
30
+ </div>
31
+ <div class="container">
32
+ <div class="alert alert-warning">
33
+ <p>Your application layout is unmodified. Please edit me!
34
+ Visit me in app/views/layouts/application.html.erb.</p>
35
+ </div>
36
+ <% unless controller.action_name =~ /(new|edit)/ %>
37
+ <%= render_breadcrumbs %>
38
+ <% end %>
39
+ <%= show_flash %>
40
+ <%= yield %>
41
+ </div>
42
+
43
+ </body>
44
+ </html>
@@ -0,0 +1,66 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+ before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
8
+ before_action :add_breadcrumb_show, only: [:show]
9
+
10
+ # GET <%= route_url %>
11
+ def index
12
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
13
+ respond_with(@<%= plural_table_name %>)
14
+ end
15
+
16
+ # GET <%= route_url %>/1
17
+ def show
18
+ respond_with(@<%= singular_table_name %>)
19
+ end
20
+
21
+ # GET <%= route_url %>/new
22
+ def new
23
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
24
+ respond_with(@<%= singular_table_name %>)
25
+ end
26
+
27
+ # GET <%= route_url %>/1/edit
28
+ def edit
29
+ end
30
+
31
+ # POST <%= route_url %>
32
+ def create
33
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
34
+
35
+ @<%= orm_instance.save %>
36
+ respond_with(@<%= singular_table_name %>)
37
+ end
38
+
39
+ # PATCH/PUT <%= route_url %>/1
40
+ def update
41
+ @<%= orm_instance.update("#{singular_table_name}_params") %>
42
+ respond_with(@<%= singular_table_name %>)
43
+ end
44
+
45
+ # DELETE <%= route_url %>/1
46
+ def destroy
47
+ @<%= orm_instance.destroy %>
48
+ respond_with(@<%= singular_table_name %>)
49
+ end
50
+
51
+ private
52
+ # Use callbacks to share common setup or constraints between actions.
53
+ def set_<%= singular_table_name %>
54
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
55
+ end
56
+
57
+ # Only allow a trusted parameter "white list" through.
58
+ def <%= "#{singular_table_name}_params" %>
59
+ <%- if attributes_names.empty? -%>
60
+ params[:<%= singular_table_name %>]
61
+ <%- else -%>
62
+ params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
63
+ <%- end -%>
64
+ end
65
+ end
66
+ <% end -%>