express_admin 1.3.0 → 1.3.1

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/fonts/ionicons.eot +0 -0
  3. data/app/assets/fonts/ionicons.svg +1028 -697
  4. data/app/assets/fonts/ionicons.ttf +0 -0
  5. data/app/assets/fonts/ionicons.woff +0 -0
  6. data/app/assets/stylesheets/express_admin/components/_h_box.sass +2 -0
  7. data/app/assets/stylesheets/express_admin/components/_v_box.sass +2 -0
  8. data/app/assets/stylesheets/express_admin/plugins/_select2.sass +4 -0
  9. data/app/assets/stylesheets/express_admin/screen.sass +3 -0
  10. data/app/assets/stylesheets/express_admin/shared/_icons.sass +2 -0
  11. data/app/assets/stylesheets/express_admin/shared/_tables.sass +3 -3
  12. data/app/assets/stylesheets/ionicons/ionicons.scss +2968 -0
  13. data/app/components/express_admin/h_box.rb +11 -0
  14. data/app/components/express_admin/icon.rb +7 -0
  15. data/app/components/express_admin/icon_link.rb +34 -0
  16. data/app/components/express_admin/layout_component.rb +37 -0
  17. data/app/components/express_admin/pane.rb +4 -4
  18. data/app/components/express_admin/smart_form.rb +2 -1
  19. data/app/components/express_admin/smart_table.rb +16 -4
  20. data/app/components/express_admin/v_box.rb +10 -0
  21. data/app/views/layouts/express_admin/admin.html.et +1 -1
  22. data/app/views/shared/express_admin/_navigation_bar.html.et +6 -3
  23. data/config/initializers/request_store_current_user.rb +9 -0
  24. data/lib/express_admin/routes.rb +17 -0
  25. data/lib/express_admin/version.rb +1 -1
  26. data/lib/express_admin.rb +1 -0
  27. data/lib/generators/express_admin/install/install_generator.rb +1 -1
  28. data/lib/generators/express_admin/install/templates/controllers/admin_controller.rb.erb +19 -21
  29. data/lib/generators/express_admin/scaffold/scaffold_generator.rb +5 -30
  30. data/lib/generators/express_admin/scaffold/templates/controller/controller.rb +6 -8
  31. data/lib/generators/express_admin/scaffold/templates/index.html.et.erb +6 -8
  32. data/test/dummy/db/test.sqlite3 +0 -0
  33. data/test/dummy/log/test.log +2556 -0
  34. data/test/lib/generators/express_admin/install_generator_test.rb +1 -1
  35. data/test/lib/generators/express_admin/scaffold_generator_test.rb +4 -6
  36. data/vendor/gems/express_templates/express_templates-0.7.0.gem +0 -0
  37. data/vendor/gems/express_templates/express_templates-0.7.1.gem +0 -0
  38. data/vendor/gems/express_templates/lib/arbre/patches.rb +13 -1
  39. data/vendor/gems/express_templates/lib/express_templates/components/capabilities/resourceful.rb +9 -1
  40. data/vendor/gems/express_templates/lib/express_templates/components/forms/select.rb +17 -7
  41. data/vendor/gems/express_templates/lib/express_templates/components/forms/submit.rb +1 -1
  42. data/vendor/gems/express_templates/lib/express_templates/version.rb +1 -1
  43. data/vendor/gems/express_templates/test/components/forms/express_form_test.rb +1 -1
  44. data/vendor/gems/express_templates/test/components/forms/select_test.rb +1 -1
  45. data/vendor/gems/express_templates/test/components/forms/submit_test.rb +16 -1
  46. data/vendor/gems/express_templates/test/dummy/log/test.log +1575 -0
  47. metadata +30 -5
  48. data/app/assets/stylesheets/ionicons/ionicons.sass +0 -1873
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), 'layout_component')
2
+ module ExpressAdmin
3
+ class HBox < LayoutComponent
4
+
5
+ emits -> (contents) {
6
+ div(container_div_attributes) {
7
+ contents.call(self) if contents
8
+ }
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module ExpressAdmin
2
+ class Icon < ExpressTemplates::Components::Configurable
3
+ emits -> {
4
+ i(class: "icon ion-#{config[:id]}")
5
+ }
6
+ end
7
+ end
@@ -0,0 +1,34 @@
1
+ module ExpressAdmin
2
+ class IconLink < ExpressTemplates::Components::Configurable
3
+
4
+ emits -> {
5
+ if config[:right]
6
+ a(anchor_args) {
7
+ text_node config[:text]
8
+ icon(config[:icon_name].to_sym)
9
+ }
10
+ else
11
+ a(anchor_args) {
12
+ icon(config[:icon_name].to_sym)
13
+ text_node config[:text]
14
+ }
15
+ end
16
+ }
17
+
18
+ def anchor_args
19
+ args = {class: class_list,
20
+ href: config[:href]}
21
+ args[:id] = config[:id] if config[:id]
22
+ args[:target] = config[:target] if config[:target]
23
+ args['data-delete'] = config[:delete] if config[:delete]
24
+ args['data-confirm'] = config[:confirm] if config[:confirm]
25
+ args[:title] = config[:title] if config[:title]
26
+ args
27
+ end
28
+
29
+ def icon_options
30
+ [:icon_name, :text, :right]
31
+ end
32
+
33
+ end
34
+ end
@@ -1,7 +1,44 @@
1
1
  module ExpressAdmin
2
2
  class LayoutComponent < ExpressTemplates::Components::Configurable
3
+
3
4
  def dom_id
4
5
  config.try(:[], :id)
5
6
  end
7
+
8
+ def component_options
9
+ [:id, :class, :style] + supported_style_options
10
+ end
11
+
12
+ def component_classes
13
+ add_class config[:id].to_s
14
+ add_class config[:class]
15
+ class_names
16
+ end
17
+
18
+ def supported_style_options
19
+ [:height, :width]
20
+ end
21
+
22
+ def provided_style_attributes
23
+ config.select {|k,v| supported_style_options.include?(k) }
24
+ end
25
+
26
+ def style_attributes
27
+ attribs = config[:style] || {}
28
+ attribs.merge(provided_style_attributes).map do |k, v|
29
+ "#{k}: #{v}"
30
+ end.join('; ')
31
+ end
32
+
33
+ def pass_along_attributes
34
+ config.reject {|k,v| component_options.include?(k) }
35
+ end
36
+
37
+ def container_div_attributes
38
+ pass_along_attributes
39
+ .merge(id: dom_id, class: component_classes)
40
+ .merge(style: style_attributes)
41
+ end
42
+
6
43
  end
7
44
  end
@@ -4,7 +4,7 @@ module ExpressAdmin
4
4
  class Pane < LayoutComponent
5
5
 
6
6
  emits -> (block) {
7
- div(id: dom_id, class: pane_classes) {
7
+ div(container_div_attributes) {
8
8
  heading if title || status
9
9
  block.call(self) if block
10
10
  }
@@ -31,9 +31,9 @@ module ExpressAdmin
31
31
  config[:status] || nil
32
32
  end
33
33
 
34
- def pane_classes
35
- add_class config[:id].to_s
36
- class_names
34
+ def component_options
35
+ super +
36
+ [:title, :status]
37
37
  end
38
38
 
39
39
  end
@@ -32,7 +32,8 @@ module ExpressAdmin
32
32
  'check_box' => 'checkbox'}
33
33
  field_type = attrib.field_type.to_s.sub(/_field$/,'')
34
34
  if relation = attrib.name.match(/(\w+)_id$/).try(:[], 1)
35
- select(attrib.name, config["#{relation}_collection".to_sym], select2: true)
35
+ # TODO: should allow select2 override
36
+ select(attrib.name, options: config["#{relation}_collection".to_sym], select2: true)
36
37
  else
37
38
  if field_type == 'text_area'
38
39
  textarea attrib.name.to_sym, rows: 10
@@ -20,7 +20,7 @@ module ExpressAdmin
20
20
  }
21
21
  }
22
22
  tbody {
23
- helpers.collection.each do |item|
23
+ collection.each do |item|
24
24
  tr(id: row_id(item), class: row_class(item)) {
25
25
  display_columns.each do |column|
26
26
  td(class: column.name) {
@@ -55,9 +55,21 @@ module ExpressAdmin
55
55
  helpers.send(resource_path_helper, item.to_param)
56
56
  end
57
57
 
58
+ def should_show_delete?(item)
59
+ if item.respond_to?(:can_delete?) && item.can_delete?
60
+ true
61
+ elsif !item.respond_to?(:can_delete?)
62
+ true
63
+ else
64
+ false
65
+ end
66
+ end
67
+
58
68
  def actions_column(item)
59
69
  td {
60
- link_to 'Delete', resource_path(item), method: :delete, data: {confirm: 'Are you sure?'}, class: 'button small secondary'
70
+ if should_show_delete?(item)
71
+ link_to 'Delete', resource_path(item), method: :delete, data: {confirm: 'Are you sure?'}, class: 'button small secondary'
72
+ end
61
73
  }
62
74
  end
63
75
 
@@ -80,13 +92,13 @@ module ExpressAdmin
80
92
  def cell_value(item, accessor)
81
93
  if accessor.respond_to?(:call)
82
94
  value = begin
83
- helpers.instance_eval "(#{accessor.source}).call(item).to_s"
95
+ eval "(#{accessor.source}).call(item).to_s"
84
96
  rescue
85
97
  'Error: '+$!.to_s
86
98
  end
87
99
  elsif attrib = accessor.to_s.match(/(\w+)_link$/).try(:[], 1)
88
100
  # TODO: only works with non-namespaced routes
89
- value = helpers.link_to item.send(attrib), helpers.resource_path(item)
101
+ value = helpers.link_to item.send(attrib), resource_path(item)
90
102
  elsif attrib = accessor.to_s.match(/(\w+)_in_words/).try(:[], 1)
91
103
  value = item.send(attrib) ? (helpers.time_ago_in_words(item.send(attrib))+' ago') : 'never'
92
104
  else
@@ -0,0 +1,10 @@
1
+ module ExpressAdmin
2
+ class VBox < LayoutComponent
3
+
4
+ emits -> (contents) {
5
+ div(container_div_attributes) {
6
+ contents.call(self) if contents
7
+ }
8
+ }
9
+ end
10
+ end
@@ -2,7 +2,7 @@
2
2
  html {
3
3
  head {
4
4
  title { title_content }
5
- meta(name: "description", content: "#{description_meta_content}")
5
+ meta(name: "description", content: "#{helpers.description_meta_content}")
6
6
  meta(name: "viewport", content: "width=device-width, initial-scale=1.0")
7
7
  admin_javascript_and_css_includes
8
8
  yield(:page_css)
@@ -7,8 +7,11 @@ nav(class: 'top-bar') {
7
7
  }
8
8
  }
9
9
  mega_menu_component
10
- li { link_to 'View Site', '/', target: '_blank' }
11
- li { flash_message_component }
10
+ li {
11
+ icon_link(icon_name: 'android-open', text: 'View Site', href: '/', target: '_blank')
12
+ }
13
+ render(partial: 'shared/nav_bar_actions')
14
+ li { flash_message_component } unless helpers.flash.empty?
12
15
  }
13
16
  }
14
17
  div(class: 'secondary-menu') {
@@ -16,7 +19,7 @@ nav(class: 'top-bar') {
16
19
  li {
17
20
  a {
18
21
  current_user_gravatar
19
- span {'Profile' }
22
+ span {'Profile' }
20
23
  }
21
24
  sign_in_or_sign_out
22
25
  }
@@ -0,0 +1,9 @@
1
+ class ApplicationController < ActionController::Base
2
+
3
+ if defined? Devise
4
+ before_filter do
5
+ RequestStore[:current_user] = current_user
6
+ end
7
+ end
8
+
9
+ end
@@ -0,0 +1,17 @@
1
+ module ExpressAdmin
2
+ class Routes
3
+ def self.register(&block)
4
+ registered_route_blocks << block
5
+ end
6
+
7
+ def self.registered_route_blocks
8
+ @blocks ||= []
9
+ end
10
+
11
+ def self.draw(application_routes)
12
+ registered_route_blocks.each do |route_block|
13
+ application_routes.instance_eval(&route_block)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module ExpressAdmin
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
data/lib/express_admin.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), "core_extensions/string_promptify")
2
2
  require "express_admin/engine"
3
+ require "express_admin/routes"
3
4
 
4
5
  module ExpressAdmin
5
6
  end
@@ -21,7 +21,7 @@ module ExpressAdmin
21
21
 
22
22
  def create_admin_controller
23
23
  template 'controllers/admin_controller.rb.erb',
24
- File.join('app/controllers', @project_name, 'admin', 'admin_controller.rb')
24
+ File.join('app/controllers', @project_name, 'admin_controller.rb')
25
25
  end
26
26
 
27
27
  def create_admin_layout
@@ -1,34 +1,32 @@
1
1
  require_dependency "application_controller"
2
2
 
3
3
  module <%= project_class %>
4
- module Admin
5
- class AdminController < ApplicationController
6
- inherit_resources # Use inherited_resources
4
+ class AdminController < ApplicationController
5
+ inherit_resources # Use inherited_resources
7
6
 
8
- helper ::ExpressAdmin::AdminHelper
9
- before_filter :authenticate_user! if defined?(Devise)
10
- layout "<%= project_name %>/admin"
7
+ helper ::ExpressAdmin::AdminHelper
8
+ before_filter :authenticate_user! if defined?(Devise)
9
+ layout "<%= project_name %>/admin"
11
10
 
12
- before_filter :load_collection, only: [:show]
13
- before_filter :build_new_resource, only: [:index]
11
+ before_filter :load_collection, only: [:show]
12
+ before_filter :build_new_resource, only: [:index]
14
13
 
15
- def show
16
- show! do |format|
17
- format.html { render :index }
18
- end
14
+ def show
15
+ show! do |format|
16
+ format.html { render :index }
19
17
  end
18
+ end
20
19
 
21
- private
20
+ private
22
21
 
23
- def load_collection
24
- collection # from InheritedResources
25
- end
22
+ def load_collection
23
+ collection # from InheritedResources
24
+ end
26
25
 
27
- def build_new_resource
28
- @resource_params = {}
29
- build_resource
30
- end
26
+ def build_new_resource
27
+ @resource_params = {}
28
+ build_resource
29
+ end
31
30
 
32
- end
33
31
  end
34
32
  end
@@ -20,7 +20,7 @@ module ExpressAdmin
20
20
  end
21
21
 
22
22
  def generate_controller
23
- controller_file_path = File.join(["app/controllers", project_name, admin_controller_path, "#{controller_file_name}_controller.rb"].compact)
23
+ controller_file_path = File.join(["app/controllers", project_name, "#{controller_file_name}_controller.rb"].compact)
24
24
  template "controller/controller.rb", controller_file_path
25
25
  end
26
26
 
@@ -30,23 +30,9 @@ module ExpressAdmin
30
30
  inject_into_file 'config/routes.rb', " resources :#{controller_file_name}\n",
31
31
  after: "scope '#{project_path}' do\n"
32
32
  else
33
- # this whole thing needs reworking for admin controllers
34
- # in applications
35
- if module_name # <-- should be namespaced?
36
- admin_route = <<-EOD
37
- namespace :admin do
38
- scope '#{module_name}' do
39
- resources :#{controller_file_name}, except: [:edit]
40
- end
41
- end
42
- EOD
43
- else
44
- admin_route = <<-EOD
45
- namespace :admin do
46
- resources :#{controller_file_name}, except: [:edit]
47
- end
33
+ admin_route = <<-EOD
34
+ resources :#{controller_file_name}, except: [:edit]
48
35
  EOD
49
- end
50
36
  inject_into_file 'config/routes.rb', admin_route,
51
37
  after: "#{namespaced?}::Engine.routes.draw do\n"
52
38
  end
@@ -54,7 +40,7 @@ EOD
54
40
 
55
41
  def add_menu_item
56
42
  path = if namespaced?
57
- "#{namespaced?.to_s.underscore}.#{project_name}_admin_#{controller_file_name}_path"
43
+ "#{controller_file_name}_path"
58
44
  else
59
45
  "admin_#{controller_file_name}_path"
60
46
  end
@@ -95,17 +81,6 @@ menu_entry = %Q(
95
81
  controller_class_path.last if controller_class_path.size.eql?(2)
96
82
  end
97
83
 
98
- def admin_controller_path
99
- # place the generated controller into an Admin module
100
- acp = controller_class_path.dup
101
- if acp.empty?
102
- acp.push 'admin'
103
- else
104
- acp.insert(1,'admin').compact.slice(1..-1)
105
- end
106
- File.join acp
107
- end
108
-
109
84
  def model_class_name
110
85
  class_path_parts = class_name.split("::")
111
86
  class_path_parts.unshift namespace.to_s if namespaced?
@@ -113,7 +88,7 @@ menu_entry = %Q(
113
88
  end
114
89
 
115
90
  def admin_view_path
116
- path_parts = ["app/views", project_name, admin_controller_path, controller_file_name]
91
+ path_parts = ["app/views", project_name, controller_file_name]
117
92
  File.join path_parts.compact
118
93
  end
119
94
 
@@ -1,14 +1,12 @@
1
1
  <% module_namespacing do -%>
2
- module Admin
3
- class <%= controller_class_name %>Controller < AdminController
2
+ class <%= controller_class_name %>Controller < AdminController
4
3
 
5
- defaults resource_class: <%= model_class_name %>
4
+ defaults resource_class: <%= model_class_name %>
6
5
 
7
- private
6
+ private
8
7
 
9
- def <%= singular_table_name %>_params
10
- params.require(:<%= singular_table_name %>).permit!
11
- end
12
- end
8
+ def <%= singular_table_name %>_params
9
+ params.require(:<%= singular_table_name %>).permit!
10
+ end
13
11
  end
14
12
  <% end -%>
@@ -1,10 +1,8 @@
1
- row {
2
- main_region {
3
- smart_table(:<%= plural_table_name %>, show_on_click: true)
4
- }
5
- sidebar_region {
6
- widget_box(:<%= singular_table_name %>) {
7
- smart_form(:<%= singular_table_name %>)
8
- }
1
+ main_region {
2
+ smart_table(:<%= plural_table_name %>)
3
+ }
4
+ sidebar_region {
5
+ widget_box(:<%= singular_table_name %>) {
6
+ smart_form(:<%= singular_table_name %>)
9
7
  }
10
8
  }
Binary file