rails-add_ons 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +24 -0
- data/app/assets/config/rails_add_ons_manifest.js +0 -0
- data/app/assets/javascripts/rails/add_ons/application/widgets.js.coffee +48 -0
- data/app/assets/javascripts/rails/add_ons/application.js +17 -0
- data/app/assets/javascripts/rails_add_ons.js +1 -0
- data/app/assets/stylesheets/rails/add_ons/application/bootstrap_overrides.scss +3 -0
- data/app/assets/stylesheets/rails/add_ons/application/table_monospaced.scss +3 -0
- data/app/assets/stylesheets/rails/add_ons/application/widgets.scss +5 -0
- data/app/assets/stylesheets/rails/add_ons/application.scss +4 -0
- data/app/assets/stylesheets/rails/add_ons/bootstrap_v3_flex_extension.scss +13 -0
- data/app/assets/stylesheets/rails/add_ons/font_awesome.css +3 -0
- data/app/assets/stylesheets/rails_add_ons.css +3 -0
- data/app/caches/api/cache.rb +24 -0
- data/app/components/component/base.rb +24 -0
- data/app/components/component/collection_table.rb +80 -0
- data/app/components/component/resource_table.rb +25 -0
- data/app/concerns/api_controller_concerns/exception_handling.rb +24 -0
- data/app/concerns/resources_controller/pagination.rb +15 -0
- data/app/concerns/resources_controller/sorting.rb +15 -0
- data/app/controllers/api/resources_controller/base.rb +254 -0
- data/app/controllers/api/service_controller/base.rb +73 -0
- data/app/controllers/rails/add_ons/widgets_controller.rb +10 -0
- data/app/controllers/resources_controller/base.rb +180 -0
- data/app/controllers/service_controller/base.rb +135 -0
- data/app/extensions/object_extensions.rb +8 -0
- data/app/helpers/rails/add_ons/table_helper.rb +50 -0
- data/app/helpers/rails/add_ons/widget_helper.rb +10 -0
- data/app/parsers/api/resources_controller/condition_parser.rb +65 -0
- data/app/services/rails/add_ons/service/base.rb +156 -0
- data/app/services/rails/add_ons/service/result/base.rb +25 -0
- data/app/views/component/_collection_table.haml +20 -0
- data/app/views/component/_resource_table.haml +15 -0
- data/app/views/frontend/_navbar.haml +23 -0
- data/app/views/layouts/rails/add_ons/application.haml +23 -0
- data/app/views/resources_controller/base/_after_show_table.haml +0 -0
- data/app/views/resources_controller/base/_before_show_table.haml +0 -0
- data/app/views/resources_controller/base/_form.haml +2 -0
- data/app/views/resources_controller/base/_form_buttons.haml +4 -0
- data/app/views/resources_controller/base/_form_errors.haml +6 -0
- data/app/views/resources_controller/base/_pagination.haml +4 -0
- data/app/views/resources_controller/base/_show.haml +2 -0
- data/app/views/resources_controller/base/_show_actions.haml +6 -0
- data/app/views/resources_controller/base/_table.haml +2 -0
- data/app/views/resources_controller/base/_table_actions.haml +12 -0
- data/app/views/resources_controller/base/edit.haml +6 -0
- data/app/views/resources_controller/base/index.haml +13 -0
- data/app/views/resources_controller/base/new.haml +6 -0
- data/app/views/resources_controller/base/show.haml +10 -0
- data/app/views/service_controller/base/_create_after_service_output.haml +0 -0
- data/app/views/service_controller/base/_create_before_service_output.haml +0 -0
- data/app/views/service_controller/base/_form_buttons.haml +2 -0
- data/app/views/service_controller/base/_form_errors.haml +6 -0
- data/app/views/service_controller/base/create.haml +14 -0
- data/app/views/service_controller/base/new.haml +6 -0
- data/app/views/widget/base/_remote_load_code.html.erb +4 -0
- data/app/views/widget/base/_widget_controls.haml +3 -0
- data/app/views/widget/render.js.erb +0 -0
- data/app/widgets/widget/base.rb +92 -0
- data/config/initializers/assets.rb +7 -0
- data/config/initializers/extend_object.rb +1 -0
- data/config/locales/de.yml +39 -0
- data/config/locales/en.yml +39 -0
- data/config/routes.rb +5 -0
- data/lib/rails/add_ons/engine.rb +7 -0
- data/lib/rails/add_ons/version.rb +5 -0
- data/lib/rails/add_ons.rb +7 -0
- data/lib/rails-add_ons.rb +8 -0
- data/lib/tasks/rails/add_ons_tasks.rake +4 -0
- 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
|
File without changes
|
File without changes
|
@@ -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,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,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,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
|
File without changes
|
File without changes
|
@@ -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')
|
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 @@
|
|
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