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
@@ -0,0 +1,12 @@
1
+ en:
2
+ flash:
3
+ actions:
4
+ create:
5
+ notice: "%{resource_name} was successfully created."
6
+ alert: "%{resource_name} could not be created!"
7
+ update:
8
+ notice: "%{resource_name} was successfully updated."
9
+ alert: "%{resource_name} could not be updated!"
10
+ destroy:
11
+ notice: "%{resource_name} was successfully destroyed."
12
+ alert: "%{resource_name} could not be destroyed!"
@@ -0,0 +1,4 @@
1
+ module Wobapphelpers
2
+ VERSION = "3.1.0".freeze
3
+ RELEASEDATE = "2018-07-21".freeze
4
+ end
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+ require 'shoulda-context'
3
+ require 'wobapphelpers/breadcrumbs'
4
+
5
+ class ActionControllerTest < ActionController::TestCase
6
+ tests PostsController
7
+
8
+ should "add breadcrumb only for #index" do
9
+ get :index
10
+ assert_not session[:breadcrumbs].nil?
11
+ assert_equal 1, session[:breadcrumbs].size
12
+ assert_match "Postings", session[:breadcrumbs].last[0]
13
+ assert_match "/posts", session[:breadcrumbs].last[1]
14
+ end
15
+
16
+ should "add breadcrumb only for #show" do
17
+ post:create, params: { post: {subject: 'just a dummy'}}
18
+ post_id = assigns(:post).to_param
19
+ get :show, params: { id: post_id }
20
+ assert_not session[:breadcrumbs].nil?
21
+ assert_equal 1, session[:breadcrumbs].size
22
+ assert_match "Posting(#{post_id}", session[:breadcrumbs].last[0]
23
+ assert_match "/posts/#{post_id}", session[:breadcrumbs].last[1]
24
+ end
25
+
26
+ should "last breadcrumb get session data" do
27
+ get :index
28
+ assert_not session[:breadcrumbs].nil?
29
+ assert_match "Postings", @controller.last_breadcrumb[0]
30
+ assert_match "/posts", @controller.last_breadcrumb_url
31
+ end
32
+
33
+ should "add breadcrumbs for posts#index and posts#show" do
34
+ get :index
35
+ post :create, params: { post: {subject: 'just a dummy'} }
36
+ post_id = assigns(:post).to_param
37
+ get :show, params: { id: post_id }
38
+ assert_equal 2, session[:breadcrumbs].size
39
+ assert_match "Postings", session[:breadcrumbs].first[0]
40
+ assert_match "/posts", session[:breadcrumbs].first[1]
41
+ assert_match "Posting(#{post_id}", session[:breadcrumbs].last[0]
42
+ assert_match "/posts/#{post_id}", session[:breadcrumbs].last[1]
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ class BreadcrumbHelperHelperTest < ActionDispatch::IntegrationTest
4
+ setup do
5
+ Post.create!(subject: 'brabbel', body: 'Dies ist ein Test', user: 'wob', release: Date.today)
6
+ Post.create!(subject: 'fasel', body: 'Dies ist ein zweiter Test', user: 'wob', release: Date.today)
7
+ end
8
+
9
+ test "show breadcrumbs in posts#index" do
10
+ get home_path
11
+ get posts_path
12
+ assert_select "div#breadcrumbs" do
13
+ assert_select "[href='/home?bci=0']", title: "Home"
14
+ assert_select "[href='/posts?bci=1']", title: "Postings"
15
+ end
16
+ end
17
+
18
+ test "show back_link from breadcrumbs after some actions" do
19
+ get home_path
20
+ get posts_path
21
+ # as long as :back is not used, the test should succeed
22
+ get home_path, headers: {'HTTP_REFERER' => 'http://example.org'}
23
+ get posts_path
24
+ assert_select "[class=?]", "btn btn-secondary" do
25
+ assert_select "[href='/home?bci=2']", text: /.*Zurück/
26
+ end
27
+ end
28
+
29
+ test "show back_link :back" do
30
+ get home_path, headers: {'HTTP_REFERER' => 'http://example.org'}
31
+ assert_select "[class=?]", "btn btn-secondary" do
32
+ assert_select "[href='http://example.org']"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ class ApplicationController < ActionController::Base
2
+ include Wobapphelpers::Breadcrumbs
3
+ before_action :add_breadcrumb_index, only: [:index]
4
+
5
+ self.responder = Wobapphelpers::Responders
6
+
7
+ # Prevent CSRF attacks by raising an exception.
8
+ # For APIs, you may want to use :null_session instead.
9
+ protect_from_forgery with: :exception
10
+
11
+ respond_to :html, :json
12
+
13
+ helper_method :current_user
14
+
15
+ def current_user
16
+ @current_user = User.new
17
+ end
18
+
19
+ end
@@ -0,0 +1,55 @@
1
+ class BlogsController < ApplicationController
2
+ before_action :set_blog, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /blogs
5
+ def index
6
+ @blogs = Blog.all
7
+ respond_with(@blogs)
8
+ end
9
+
10
+ # GET /blogs/1
11
+ def show
12
+ respond_with(@blog)
13
+ end
14
+
15
+ # GET /blogs/new
16
+ def new
17
+ @blog = Blog.new
18
+ respond_with(@blog)
19
+ end
20
+
21
+ # GET /blogs/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /blogs
26
+ def create
27
+ @blog = Blog.new(blog_params)
28
+
29
+ @blog.save
30
+ respond_with(@blog)
31
+ end
32
+
33
+ # PATCH/PUT /blogs/1
34
+ def update
35
+ @blog.update(blog_params)
36
+ respond_with(@blog)
37
+ end
38
+
39
+ # DELETE /blogs/1
40
+ def destroy
41
+ @blog.destroy
42
+ respond_with(@blog)
43
+ end
44
+
45
+ private
46
+ # Use callbacks to share common setup or constraints between actions.
47
+ def set_blog
48
+ @blog = Blog.find(params[:id])
49
+ end
50
+
51
+ # Only allow a trusted parameter "white list" through.
52
+ def blog_params
53
+ params.require(:blog).permit(:subject, :body, :user, :release)
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ respond_to do |format|
4
+ format.html
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,58 @@
1
+ class PostsController < ApplicationController
2
+ before_action :set_post, only: [:show, :edit, :update, :destroy]
3
+ before_action :add_breadcrumb_show, only: [:show]
4
+
5
+ # GET /posts
6
+ def index
7
+ @posts = Post.all
8
+ flash[:success] = "Always done"
9
+ respond_with(@posts)
10
+ end
11
+
12
+ # GET /posts/1
13
+ def show
14
+ # add_breadcrumb_for(@post)
15
+ # add_breadcrumb("Posting(#{@post.id})", "/posts/#{@post.id}")
16
+ respond_with(@post)
17
+ end
18
+
19
+ # GET /posts/new
20
+ def new
21
+ @post = Post.new
22
+ respond_with(@post)
23
+ end
24
+
25
+ # GET /posts/1/edit
26
+ def edit
27
+ end
28
+
29
+ # POST /posts
30
+ def create
31
+ @post = Post.new(post_params)
32
+ @post.save
33
+ respond_with(@post)
34
+ end
35
+
36
+ # PATCH/PUT /posts/1
37
+ def update
38
+ @post.update(post_params)
39
+ respond_with(@post)
40
+ end
41
+
42
+ # DELETE /posts/1
43
+ def destroy
44
+ @post.destroy
45
+ respond_with(@post)
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_post
51
+ @post = Post.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def post_params
56
+ params.require(:post).permit(:subject, :body, :user, :release)
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module ApplicationHelper
2
+ include Wobapphelpers::Helpers::All
3
+ end
@@ -0,0 +1,2 @@
1
+ module BlogsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module PostsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class Blog < ActiveRecord::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class Post < ActiveRecord::Base
2
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+ require 'jquery-rails'
5
+
6
+ Bundler.require(*Rails.groups)
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
+ # config.time_zone = 'Central Time (US & Canada)'
17
+
18
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
+ config.i18n.default_locale = :de
21
+
22
+ config.generators do |g|
23
+ g.orm :active_record
24
+ g.template_engine :erb
25
+ g.test_framework false
26
+ g.stylesheets false
27
+ g.javascripts false
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,37 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports and disable caching.
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send.
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger.
20
+ config.active_support.deprecation = :log
21
+
22
+ # Raise an error on page load if there are pending migrations.
23
+ config.active_record.migration_error = :page_load
24
+
25
+ # Debug mode disables concatenation and preprocessing of assets.
26
+ # This option may cause significant delays in view rendering with a large
27
+ # number of complex assets.
28
+ config.assets.debug = true
29
+
30
+ # Adds additional error checking when serving assets at runtime.
31
+ # Checks for improperly declared sprockets dependencies.
32
+ # Raises helpful error messages.
33
+ config.assets.raise_runtime_errors = true
34
+
35
+ # Raises error for missing translations
36
+ # config.action_view.raise_on_missing_translations = true
37
+ end
@@ -0,0 +1,83 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # Code is not reloaded between requests.
5
+ config.cache_classes = true
6
+
7
+ # Eager load code on boot. This eager loads most of Rails and
8
+ # your application in memory, allowing both threaded web servers
9
+ # and those relying on copy on write to perform better.
10
+ # Rake tasks automatically ignore this option for performance.
11
+ config.eager_load = true
12
+
13
+ # Full error reports are disabled and caching is turned on.
14
+ config.consider_all_requests_local = false
15
+ config.action_controller.perform_caching = true
16
+
17
+ # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
+ # Add `rack-cache` to your Gemfile before enabling this.
19
+ # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
20
+ # config.action_dispatch.rack_cache = true
21
+
22
+ # Disable Rails's static asset server (Apache or nginx will already do this).
23
+ config.serve_static_assets = false
24
+
25
+ # Compress JavaScripts and CSS.
26
+ config.assets.js_compressor = :uglifier
27
+ # config.assets.css_compressor = :sass
28
+
29
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
30
+ config.assets.compile = false
31
+
32
+ # Generate digests for assets URLs.
33
+ config.assets.digest = true
34
+
35
+ # Version of your assets, change this if you want to expire all your assets.
36
+ config.assets.version = '1.0'
37
+
38
+ # Specifies the header that your server uses for sending files.
39
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
40
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
41
+
42
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
43
+ # config.force_ssl = true
44
+
45
+ # Set to :debug to see everything in the log.
46
+ config.log_level = :info
47
+
48
+ # Prepend all log lines with the following tags.
49
+ # config.log_tags = [ :subdomain, :uuid ]
50
+
51
+ # Use a different logger for distributed setups.
52
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
53
+
54
+ # Use a different cache store in production.
55
+ # config.cache_store = :mem_cache_store
56
+
57
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
58
+ # config.action_controller.asset_host = "http://assets.example.com"
59
+
60
+ # Precompile additional assets.
61
+ # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
62
+ # config.assets.precompile += %w( search.js )
63
+
64
+ # Ignore bad email addresses and do not raise email delivery errors.
65
+ # Set this to true and configure the email server for immediate delivery to raise delivery errors.
66
+ # config.action_mailer.raise_delivery_errors = false
67
+
68
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
69
+ # the I18n.default_locale when a translation cannot be found).
70
+ config.i18n.fallbacks = true
71
+
72
+ # Send deprecation notices to registered listeners.
73
+ config.active_support.deprecation = :notify
74
+
75
+ # Disable automatic flushing of the log to improve performance.
76
+ # config.autoflush_log = false
77
+
78
+ # Use default logging formatter so that PID and timestamp are not suppressed.
79
+ config.log_formatter = ::Logger::Formatter.new
80
+
81
+ # Do not dump schema after migrations.
82
+ config.active_record.dump_schema_after_migration = false
83
+ end
@@ -0,0 +1,45 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Do not eager load code on boot. This avoids loading your whole application
11
+ # just for the purpose of running a single test. If you are using a tool that
12
+ # preloads Rails for running tests, you may have to set it to true.
13
+ config.eager_load = false
14
+
15
+ # Configure static asset server for tests with Cache-Control for performance.
16
+ # config.serve_static_assets = true
17
+ config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
18
+
19
+ # Show full error reports and disable caching.
20
+ config.consider_all_requests_local = true
21
+ config.action_controller.perform_caching = false
22
+
23
+ # Raise exceptions instead of rendering exception templates.
24
+ config.action_dispatch.show_exceptions = false
25
+
26
+ # Disable request forgery protection in test environment.
27
+ config.action_controller.allow_forgery_protection = false
28
+
29
+ # Tell Action Mailer not to deliver emails to the real world.
30
+ # The :test delivery method accumulates sent emails in the
31
+ # ActionMailer::Base.deliveries array.
32
+ config.action_mailer.delivery_method = :test
33
+
34
+ # Print deprecation notices to the stderr.
35
+ config.active_support.deprecation = :stderr
36
+
37
+ # Raises error for missing translations
38
+ # config.action_view.raise_on_missing_translations = true
39
+
40
+ # -- Rails 4.2
41
+ config.active_support.test_order = :sorted
42
+ # config.serve_static_files = true
43
+ # -- rails 5.0
44
+ config.public_file_server.enabled = true
45
+ end