rails-add_ons 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +24 -0
  5. data/app/assets/config/rails_add_ons_manifest.js +0 -0
  6. data/app/assets/javascripts/rails/add_ons/application/widgets.js.coffee +48 -0
  7. data/app/assets/javascripts/rails/add_ons/application.js +17 -0
  8. data/app/assets/javascripts/rails_add_ons.js +1 -0
  9. data/app/assets/stylesheets/rails/add_ons/application/bootstrap_overrides.scss +3 -0
  10. data/app/assets/stylesheets/rails/add_ons/application/table_monospaced.scss +3 -0
  11. data/app/assets/stylesheets/rails/add_ons/application/widgets.scss +5 -0
  12. data/app/assets/stylesheets/rails/add_ons/application.scss +4 -0
  13. data/app/assets/stylesheets/rails/add_ons/bootstrap_v3_flex_extension.scss +13 -0
  14. data/app/assets/stylesheets/rails/add_ons/font_awesome.css +3 -0
  15. data/app/assets/stylesheets/rails_add_ons.css +3 -0
  16. data/app/caches/api/cache.rb +24 -0
  17. data/app/components/component/base.rb +24 -0
  18. data/app/components/component/collection_table.rb +80 -0
  19. data/app/components/component/resource_table.rb +25 -0
  20. data/app/concerns/api_controller_concerns/exception_handling.rb +24 -0
  21. data/app/concerns/resources_controller/pagination.rb +15 -0
  22. data/app/concerns/resources_controller/sorting.rb +15 -0
  23. data/app/controllers/api/resources_controller/base.rb +254 -0
  24. data/app/controllers/api/service_controller/base.rb +73 -0
  25. data/app/controllers/rails/add_ons/widgets_controller.rb +10 -0
  26. data/app/controllers/resources_controller/base.rb +180 -0
  27. data/app/controllers/service_controller/base.rb +135 -0
  28. data/app/extensions/object_extensions.rb +8 -0
  29. data/app/helpers/rails/add_ons/table_helper.rb +50 -0
  30. data/app/helpers/rails/add_ons/widget_helper.rb +10 -0
  31. data/app/parsers/api/resources_controller/condition_parser.rb +65 -0
  32. data/app/services/rails/add_ons/service/base.rb +156 -0
  33. data/app/services/rails/add_ons/service/result/base.rb +25 -0
  34. data/app/views/component/_collection_table.haml +20 -0
  35. data/app/views/component/_resource_table.haml +15 -0
  36. data/app/views/frontend/_navbar.haml +23 -0
  37. data/app/views/layouts/rails/add_ons/application.haml +23 -0
  38. data/app/views/resources_controller/base/_after_show_table.haml +0 -0
  39. data/app/views/resources_controller/base/_before_show_table.haml +0 -0
  40. data/app/views/resources_controller/base/_form.haml +2 -0
  41. data/app/views/resources_controller/base/_form_buttons.haml +4 -0
  42. data/app/views/resources_controller/base/_form_errors.haml +6 -0
  43. data/app/views/resources_controller/base/_pagination.haml +4 -0
  44. data/app/views/resources_controller/base/_show.haml +2 -0
  45. data/app/views/resources_controller/base/_show_actions.haml +6 -0
  46. data/app/views/resources_controller/base/_table.haml +2 -0
  47. data/app/views/resources_controller/base/_table_actions.haml +12 -0
  48. data/app/views/resources_controller/base/edit.haml +6 -0
  49. data/app/views/resources_controller/base/index.haml +13 -0
  50. data/app/views/resources_controller/base/new.haml +6 -0
  51. data/app/views/resources_controller/base/show.haml +10 -0
  52. data/app/views/service_controller/base/_create_after_service_output.haml +0 -0
  53. data/app/views/service_controller/base/_create_before_service_output.haml +0 -0
  54. data/app/views/service_controller/base/_form_buttons.haml +2 -0
  55. data/app/views/service_controller/base/_form_errors.haml +6 -0
  56. data/app/views/service_controller/base/create.haml +14 -0
  57. data/app/views/service_controller/base/new.haml +6 -0
  58. data/app/views/widget/base/_remote_load_code.html.erb +4 -0
  59. data/app/views/widget/base/_widget_controls.haml +3 -0
  60. data/app/views/widget/render.js.erb +0 -0
  61. data/app/widgets/widget/base.rb +92 -0
  62. data/config/initializers/assets.rb +7 -0
  63. data/config/initializers/extend_object.rb +1 -0
  64. data/config/locales/de.yml +39 -0
  65. data/config/locales/en.yml +39 -0
  66. data/config/routes.rb +5 -0
  67. data/lib/rails/add_ons/engine.rb +7 -0
  68. data/lib/rails/add_ons/version.rb +5 -0
  69. data/lib/rails/add_ons.rb +7 -0
  70. data/lib/rails-add_ons.rb +8 -0
  71. data/lib/tasks/rails/add_ons_tasks.rake +4 -0
  72. metadata +268 -0
@@ -0,0 +1,20 @@
1
+ %table{ class: table_css_classes }
2
+ %thead
3
+ %tr
4
+ - columns.each do |name, options|
5
+ - title = if resource_class.respond_to?(:human_attribute_name)
6
+ - resource_class.human_attribute_name(name)
7
+ - else
8
+ - name
9
+ - if options.has_key?(:sort)
10
+ %td= sort_link(name, title, options[:sort])
11
+ - else
12
+ %td= title
13
+ %tbody
14
+ - collection.each do |resource|
15
+ %tr
16
+ - columns.each do |name, options|
17
+ - if options[:block].present?
18
+ %td= options[:block].call(resource)
19
+ - else
20
+ %td= resource.send(name)
@@ -0,0 +1,15 @@
1
+ %table.table
2
+ - rows.each do |name, options|
3
+ %tr
4
+ - if resource_class.respond_to? :human_attribute_name
5
+ %th
6
+ = resource_class.human_attribute_name(name)
7
+ - else
8
+ %th
9
+ = name
10
+ - if options[:block].present?
11
+ %td
12
+ = options[:block].call(resource)
13
+ - else
14
+ %td
15
+ = resource.send(name)
@@ -0,0 +1,23 @@
1
+ %nav.navbar.navbar-toggleable-md.navbar-inverse.bg-inverse.fixed-top
2
+ %button.navbar-toggler.navbar-toggler-right{"aria-controls" => "navbarsExampleDefault", "aria-expanded" => "false", "aria-label" => "Toggle navigation", "data-target" => "#navbarsExampleDefault", "data-toggle" => "collapse", :type => "button"}
3
+ %span.navbar-toggler-icon
4
+ = bootstrap_navbar_brand
5
+ #navbarsExampleDefault.collapse.navbar-collapse
6
+ %ul.navbar-nav.mr-auto
7
+ %li.nav-item.active
8
+ %a.nav-link{:href => "#"}
9
+ Home
10
+ %span.sr-only (current)
11
+ %li.nav-item
12
+ %a.nav-link{:href => "#"} Link
13
+ %li.nav-item
14
+ %a.nav-link.disabled{:href => "#"} Disabled
15
+ %li.nav-item.dropdown
16
+ %a#dropdown01.nav-link.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", :href => "http://example.com"} Dropdown
17
+ .dropdown-menu{"aria-labelledby" => "dropdown01"}
18
+ %a.dropdown-item{:href => "#"} Action
19
+ %a.dropdown-item{:href => "#"} Another action
20
+ %a.dropdown-item{:href => "#"} Something else here
21
+ %form.form-inline.my-2.my-lg-0
22
+ %input.form-control.mr-sm-2{:placeholder => "Search", :type => "text"}/
23
+ %button.btn.btn-outline-success.my-2.my-sm-0{:type => "submit"} Search
@@ -0,0 +1,23 @@
1
+ !!!
2
+ %html{:lang => "en"}
3
+ %head
4
+ = csrf_meta_tags
5
+
6
+ / Required meta tags
7
+ %meta{:charset => "utf-8"}/
8
+ %meta{:content => "width=device-width, initial-scale=1, shrink-to-fit=no", :name => "viewport"}/
9
+ / Bootstrap CSS
10
+ %link{:crossorigin => "anonymous", :href => "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css", :integrity => "sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ", :rel => "stylesheet"}/
11
+ = stylesheet_link_tag "rails/add_ons/application", media: 'all', :'data-turbolinks-track' => 'reload'
12
+ = stylesheet_link_tag "rails/add_ons/font_awesome", media: 'all', :'data-turbolinks-track' => 'reload'
13
+ = javascript_include_tag "rails/add_ons/application", :'data-turbolinks-track' => 'reload'
14
+ / widget endpoint
15
+ - if respond_to?(:rails_add_ons)
16
+ %meta{name: 'widget-base-path', content: rails_add_ons.widget_path}
17
+ %body
18
+ = render 'navbar'
19
+ .container-fluid
20
+ .starter-template
21
+ = bootstrap_flash
22
+ = yield
23
+ / /.container
@@ -0,0 +1,2 @@
1
+ - resource_class.attribute_names.delete_if { |an| %w(id created_at updated_at).include?(an) }.each do |name|
2
+ = form.input name
@@ -0,0 +1,4 @@
1
+ = form.button :submit, class: 'btn btn-success' do
2
+ = fa_icon :ckeck
3
+ = bootstrap_button(to: ((action_name == 'new' || form.object.new_record?) ? collection_path : resource_path(form.object)), context: :link) do
4
+ = t('.cancel')
@@ -0,0 +1,6 @@
1
+ - if resource.errors.any?
2
+ = bootstrap_alert(context: :danger, class: 'error-explanation') do
3
+ .error-heading= t('errors.template.header', count: resource.errors.count, model: resource.class.model_name.human)
4
+ %ul
5
+ - resource.errors.full_messages.each do |msg|
6
+ %li= msg
@@ -0,0 +1,4 @@
1
+ - if respond_to?(:paginate)
2
+ = paginate @collection
3
+ - if respond_to?(:will_paginate)
4
+ = will_paginate @collection
@@ -0,0 +1,2 @@
1
+ - resource_class.attribute_names.each do |name|
2
+ = table.row name
@@ -0,0 +1,6 @@
1
+ = bootstrap_button(to: edit_resource_path(resource), context: :secondary) do
2
+ = fa_icon(:pencil)
3
+ = t('.edit')
4
+
5
+ = bootstrap_button(to: collection_path, context: :link) do
6
+ = t('.back')
@@ -0,0 +1,2 @@
1
+ - resource_class.attribute_names.each do |name|
2
+ = table.column name
@@ -0,0 +1,12 @@
1
+ = table.column :actions do |resource|
2
+ - capture_haml do
3
+ = bootstrap_button_group do
4
+ = bootstrap_button(to: resource_path(resource), context: :primary, size: :small) do
5
+ = fa_icon :eye
6
+ = t('.show')
7
+ = bootstrap_button(to: edit_resource_path(resource), context: :secondary, size: :small) do
8
+ = fa_icon :pencil
9
+ = t('.edit')
10
+ = bootstrap_button(to: resource_path(resource), context: :danger, size: :small, method: :delete, data: { confirm: 'Are you sure?' }) do
11
+ = fa_icon :trash
12
+ = t('.delete')
@@ -0,0 +1,6 @@
1
+ %h1= t('.title', inflections)
2
+
3
+ = bootstrap_form_for(@resource, url: resource_path(@resource)) do |f|
4
+ = render 'form_errors', resource: f.object
5
+ = render 'form', form: f
6
+ = render 'form_buttons', form: f
@@ -0,0 +1,13 @@
1
+ %h1
2
+ %span
3
+ = resource_class.model_name.human(count: :other)
4
+ .pull-right
5
+ = bootstrap_button(to: new_resource_path, context: :success) do
6
+ = fa_icon(:plus)
7
+ = t('.new')
8
+
9
+ = collection_table(collection: @collection) do |t|
10
+ = render 'table', table: t
11
+ = render 'table_actions', table: t
12
+
13
+ = render 'pagination' if respond_to?(:paginate?) && paginate?
@@ -0,0 +1,6 @@
1
+ %h1= t('.title', inflections)
2
+
3
+ = bootstrap_form_for(@resource, url: collection_path) do |f|
4
+ = render 'form_errors', resource: f.object
5
+ = render 'form', form: f
6
+ = render 'form_buttons', form: f
@@ -0,0 +1,10 @@
1
+ %h1= @resource.try_all(:human, :title, :name, :to_s)
2
+
3
+ = render 'before_show_table', resource: @resource
4
+
5
+ = resource_table(resource: @resource) do |t|
6
+ = render 'show', table: t
7
+
8
+ = render 'after_show_table', resource: @resource
9
+
10
+ = render 'show_actions', resource: @resource
@@ -0,0 +1,2 @@
1
+ = form.button :submit, class: 'btn btn-success' do
2
+ = fa_icon :check
@@ -0,0 +1,6 @@
1
+ - if resource.errors.any?
2
+ = bootstrap_alert(context: :danger, class: 'error-explanation') do
3
+ .error-heading= t('errors.template.header', count: resource.errors.count, model: resource.class.model_name.human)
4
+ %ul
5
+ - resource.errors.full_messages.each do |msg|
6
+ %li= msg
@@ -0,0 +1,14 @@
1
+ = render 'create_before_service_output', response: @response
2
+
3
+ %table.table.table-sm.table-striped.table-monospaced
4
+ %tbody
5
+ - @response.messages.each_with_index do |message, index|
6
+ %tr
7
+ %td= index + 1
8
+ %td= message
9
+
10
+ = render 'create_after_service_output', response: @response
11
+
12
+ = bootstrap_button(to: new_resource_path, context: :success) do
13
+ = fa_icon :back
14
+ = t('.back')
@@ -0,0 +1,6 @@
1
+ %h1= t('.title', inflections)
2
+
3
+ = bootstrap_form_for(@resource, url: create_resource_path) do |f|
4
+ = render 'form_errors', resource: f.object
5
+ = render 'form', form: f
6
+ = render 'form_buttons', form: f
@@ -0,0 +1,4 @@
1
+ <script>
2
+ widget_reloader = new window.WidgetReloader("<%= widget_dom_id %>", "<%= widget_name %>", "<%= widget_action %>");
3
+ widget_reloader.reload();
4
+ </script>
@@ -0,0 +1,3 @@
1
+ .widget-controls
2
+ %button{ type: 'button', class: 'widget-refresh btn btn-default btn-sm', 'data-refresh': dom_id, id: "widget-refresh-button-#{dom_id}" }
3
+ %i.fa.fa-refresh
File without changes
@@ -0,0 +1,92 @@
1
+ module Widget
2
+ class Base
3
+ attr_accessor :view_context
4
+
5
+ def self.default_action
6
+ :show
7
+ end
8
+
9
+ def self.helper(helper)
10
+ helpers << helper
11
+ end
12
+
13
+ def self.helpers
14
+ @helpers ||= []
15
+ end
16
+
17
+ def initialize(view_context, options = {}, &block)
18
+ options.reverse_merge!(frame: false, remote: false)
19
+
20
+ @view_context = view_context
21
+ @options = options
22
+ @block = block
23
+ @view_options = {}
24
+
25
+ @remote = options.delete(:remote)
26
+ @frame = options.delete(:frame)
27
+
28
+ add_helpers_to_view_context
29
+ end
30
+
31
+ def render(action = nil)
32
+ action ||= self.class.default_action
33
+ send(action)
34
+ output = ""
35
+ output << @view_context.content_tag(:div, class: widget_classes, id: dom_id, :'data-widget' => widget_name, :'data-widgetaction' => action, :'data-container' => container_dom_id) do
36
+ @view_context.render(partial: '/widget/base/widget_controls', formats: [:html], locals: { dom_id: dom_id}) +
37
+ @view_context.render(partial: partial_path(action), formats: [:html], locals: view_locals) unless @remote
38
+ end
39
+ output << remote_load_code(action) if @remote
40
+ output.html_safe
41
+ end
42
+
43
+ private
44
+
45
+ def widget_classes
46
+ classes = ["widget", "widget-#{dom_id}"]
47
+ classes << "widget-frame" if @frame
48
+ classes
49
+ end
50
+
51
+ def add_helpers_to_view_context
52
+ self.class.helpers.each do |helper|
53
+ @view_context.class_eval { include helper }
54
+ end
55
+ end
56
+
57
+ def remote_load_code(action)
58
+ @view_context.render(partial: '/widget/base/remote_load_code', locals: { widget_dom_id: dom_id, widget_action: action, widget_name: widget_name})
59
+ end
60
+
61
+ def view_options
62
+ { locals: view_locals }
63
+ end
64
+
65
+ def view_locals
66
+ (instance_variables - excluded_instance_variables).each_with_object({}) do |var_name, memo|
67
+ memo[var_name.to_s[1..-1].to_sym] = instance_variable_get(var_name)
68
+ end
69
+ end
70
+
71
+ def excluded_instance_variables
72
+ [:@view_context, :@options, :@block, :@view_options]
73
+ end
74
+
75
+ def partial_path(action)
76
+ "#{self.class.name.underscore}/#{action}"
77
+ end
78
+
79
+ def widget_name
80
+ self.class.name.underscore
81
+ end
82
+
83
+
84
+ def dom_id
85
+ "#{container_dom_id}_#{widget_name.gsub('/', '_')}"
86
+ end
87
+
88
+ def container_dom_id
89
+ @options[:container_name].try(:underscore) || 'default'
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,7 @@
1
+ Rails.application.config.assets.precompile += %w(
2
+ rails_add_ons.css
3
+ rails_add_ons.js
4
+ rails/add_ons/application.css
5
+ rails/add_ons/application.js
6
+ rails/add_ons/font_awesome.css
7
+ )
@@ -0,0 +1 @@
1
+ Object.send(:include, ObjectExtensions)
@@ -0,0 +1,39 @@
1
+ de:
2
+ classes:
3
+ i18n: Sprache
4
+ component:
5
+ collection_table:
6
+ delete: Löschen
7
+ edit: Bearbeiten
8
+ show: Anzeigen
9
+ flash:
10
+ actions:
11
+ create:
12
+ notice: "%{resource_name} wurde erstellt."
13
+ update:
14
+ notice: "%{resource_name} wurde aktualisiert."
15
+ destroy:
16
+ notice: "%{resource_name} wurde gelöscht."
17
+ alert: "%{resource_name} konnte nicht gelöscht werden."
18
+ i18n:
19
+ locales:
20
+ en: English
21
+ resources_controller:
22
+ base:
23
+ form_buttons:
24
+ cancel: "Abbrechen"
25
+ edit:
26
+ title: "%{resource_name} bearbeiten"
27
+ index:
28
+ new: "Erstellen"
29
+ new:
30
+ title: "%{resource_name} erstellen"
31
+ show_actions:
32
+ back: "Zurück"
33
+ edit: "Bearbeiten"
34
+ service_controller:
35
+ base:
36
+ create:
37
+ back: "Zurück"
38
+ new:
39
+ title: "%{service_name} ausführen"
@@ -0,0 +1,39 @@
1
+ en:
2
+ classes:
3
+ i18n: Language
4
+ component:
5
+ collection_table:
6
+ delete: Delete
7
+ edit: Edit
8
+ show: Show
9
+ flash:
10
+ actions:
11
+ create:
12
+ notice: "%{resource_name} was successfully created."
13
+ update:
14
+ notice: "%{resource_name} was successfully updated."
15
+ destroy:
16
+ notice: "%{resource_name} was successfully destroyed."
17
+ alert: "%{resource_name} could not be destroyed."
18
+ i18n:
19
+ locales:
20
+ de: Deutsch
21
+ resources_controller:
22
+ base:
23
+ form_buttons:
24
+ cancel: "Cancel"
25
+ edit:
26
+ title: "Edit %{resource_name}"
27
+ index:
28
+ new: "New"
29
+ new:
30
+ title: "New %{resource_name}"
31
+ show_actions:
32
+ back: "Back"
33
+ edit: "Edit"
34
+ service_controller:
35
+ base:
36
+ create:
37
+ back: "Back"
38
+ new:
39
+ title: "Run %{service_name}"
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Rails::AddOns::Engine.routes.draw do
2
+ resource :widget, only: [:show] do
3
+ post ':name' => :remote_render, on: :collection, as: :render
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Rails
2
+ module AddOns
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Rails::AddOns
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Rails
2
+ module AddOns
3
+ VERSION = '0.2.0'
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require "rails/add_ons/engine"
2
+
3
+ module Rails
4
+ module AddOns
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require 'haml-rails'
2
+ require 'font-awesome-rails'
3
+ require 'twitter_bootstrap_components_rails'
4
+ require 'simple_form'
5
+ require 'responders' if Rails::VERSION::MAJOR > 3
6
+ require 'rails-i18n'
7
+
8
+ require 'rails/add_ons'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rails_add_ons do
3
+ # # Task goes here
4
+ # end