brightcontent-core 2.0.33 → 2.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 (105) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/app/assets/javascripts/brightcontent/brightcontent.js.erb +8 -0
  4. data/app/assets/javascripts/brightcontent/core.js.coffee +28 -0
  5. data/app/assets/javascripts/brightcontent/wysithtml5-parser-rules.js +519 -0
  6. data/app/assets/stylesheets/brightcontent/brightcontent.css.erb +10 -0
  7. data/app/assets/stylesheets/brightcontent/core.css.sass +61 -0
  8. data/app/assets/stylesheets/brightcontent/signin.css.sass +34 -0
  9. data/app/controllers/brightcontent/admin_users_controller.rb +1 -3
  10. data/app/controllers/brightcontent/application_controller.rb +12 -2
  11. data/app/controllers/brightcontent/base_controller.rb +7 -18
  12. data/app/controllers/brightcontent/sessions_controller.rb +1 -1
  13. data/app/helpers/brightcontent/application_helper.rb +4 -0
  14. data/app/helpers/brightcontent/base_helper.rb +6 -18
  15. data/app/helpers/brightcontent/translation_helper.rb +38 -0
  16. data/app/views/brightcontent/application/_menu.html.erb +9 -2
  17. data/app/views/brightcontent/application/_resource.html.erb +3 -0
  18. data/app/views/brightcontent/application/_show_flash_names.html.erb +2 -1
  19. data/app/views/brightcontent/application/_user_menu.html.erb +4 -0
  20. data/app/views/brightcontent/base/_form.html.erb +16 -11
  21. data/app/views/brightcontent/base/_list_actions.html.erb +2 -2
  22. data/app/views/brightcontent/base/_list_filters.html.erb +12 -0
  23. data/app/views/brightcontent/base/_list_header.html.erb +6 -0
  24. data/app/views/brightcontent/base/_list_item.html.erb +6 -0
  25. data/app/views/brightcontent/base/edit.html.erb +0 -2
  26. data/app/views/brightcontent/{fields → base/form_fields}/_file.html.erb +0 -0
  27. data/app/views/brightcontent/base/index.html.erb +9 -11
  28. data/app/views/brightcontent/base/list_fields/_boolean.html.erb +5 -0
  29. data/app/views/brightcontent/base/new.html.erb +0 -2
  30. data/app/views/brightcontent/sessions/new.html.erb +5 -11
  31. data/app/views/layouts/brightcontent/application.html.erb +34 -29
  32. data/bin/autospec +16 -0
  33. data/bin/rspec +16 -0
  34. data/brightcontent-core.gemspec +11 -6
  35. data/config/initializers/simple_form.rb +18 -15
  36. data/config/initializers/simple_form_bootstrap.rb +46 -30
  37. data/config/locales/brightcontent_core.en.yml +30 -0
  38. data/config/locales/brightcontent_core.nl.yml +30 -0
  39. data/config/routes.rb +1 -1
  40. data/db/migrate/20121206121725_create_brightcontent_admin_users.rb +1 -1
  41. data/lib/brightcontent/base_controller_ext/default_actions.rb +35 -0
  42. data/lib/brightcontent/base_controller_ext/fields.rb +36 -0
  43. data/lib/brightcontent/base_controller_ext/filtering.rb +21 -0
  44. data/lib/brightcontent/base_controller_ext/pagination.rb +29 -0
  45. data/lib/brightcontent/base_controller_ext.rb +8 -0
  46. data/lib/brightcontent/core.rb +24 -10
  47. data/lib/brightcontent/engine.rb +6 -0
  48. data/lib/brightcontent/resource.rb +15 -0
  49. data/lib/brightcontent/resources.rb +25 -0
  50. data/lib/brightcontent/routes_parser.rb +9 -17
  51. data/lib/brightcontent/view_lookup/abstract.rb +49 -0
  52. data/lib/brightcontent/view_lookup/filter_field.rb +57 -0
  53. data/lib/brightcontent/view_lookup/form_field.rb +14 -0
  54. data/lib/brightcontent/view_lookup/list_field.rb +13 -0
  55. data/lib/brightcontent/view_lookup.rb +8 -0
  56. data/lib/generators/brightcontent/templates/brightcontent_controller.rb +1 -1
  57. data/lib/generators/brightcontent/templates/initializer.rb +14 -2
  58. data/spec/dummy/app/controllers/brightcontent/blogs_controller.rb +1 -1
  59. data/spec/dummy/app/models/author.rb +7 -0
  60. data/spec/dummy/app/models/blog.rb +2 -1
  61. data/spec/dummy/config/application.rb +2 -6
  62. data/spec/dummy/config/environments/development.rb +1 -10
  63. data/spec/dummy/config/environments/production.rb +0 -4
  64. data/spec/dummy/config/environments/test.rb +2 -6
  65. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  66. data/spec/dummy/db/migrate/20130720211920_create_comments.rb +0 -1
  67. data/spec/dummy/db/migrate/20140512085432_add_author_id_to_blogs.rb +5 -0
  68. data/spec/dummy/db/migrate/20140512090832_create_authors.rb +9 -0
  69. data/spec/dummy/db/schema.rb +19 -12
  70. data/spec/factories.rb +15 -0
  71. data/spec/features/login_spec.rb +3 -3
  72. data/spec/features/menu_spec.rb +2 -4
  73. data/spec/features/nested_resource_spec.rb +1 -1
  74. data/spec/features/resources_form_spec.rb +1 -3
  75. data/spec/features/resources_index_spec.rb +30 -6
  76. data/spec/helpers/brightcontent/translation_helper_spec.rb +27 -0
  77. data/spec/lib/brightcontent/model_extensions_spec.rb +1 -1
  78. data/spec/lib/brightcontent/resource_spec.rb +16 -0
  79. data/spec/lib/brightcontent/resources_spec.rb +67 -0
  80. data/spec/lib/brightcontent/routes_parser_spec.rb +4 -9
  81. data/spec/lib/brightcontent/view_lookup/abstract_spec.rb +40 -0
  82. metadata +159 -70
  83. data/app/assets/images/brightcontent/.gitkeep +0 -0
  84. data/app/assets/images/brightcontent/glyphicons-halflings-white.png +0 -0
  85. data/app/assets/images/brightcontent/glyphicons-halflings.png +0 -0
  86. data/app/assets/javascripts/brightcontent/attachments.js +0 -0
  87. data/app/assets/javascripts/brightcontent/bootstrap.min.js +0 -6
  88. data/app/assets/javascripts/brightcontent/brightcontent.js +0 -21
  89. data/app/assets/javascripts/brightcontent/main.js +0 -26
  90. data/app/assets/javascripts/brightcontent/pages.js +0 -0
  91. data/app/assets/stylesheets/brightcontent/attachments.css +0 -0
  92. data/app/assets/stylesheets/brightcontent/bootstrap-responsive.min.css +0 -9
  93. data/app/assets/stylesheets/brightcontent/bootstrap.min.css +0 -9
  94. data/app/assets/stylesheets/brightcontent/brightcontent.css +0 -19
  95. data/app/assets/stylesheets/brightcontent/main.css +0 -95
  96. data/app/assets/stylesheets/brightcontent/pages.css +0 -0
  97. data/app/views/brightcontent/base/_index_top.html.erb +0 -0
  98. data/app/views/brightcontent/base/_list.html.erb +0 -8
  99. data/app/views/brightcontent/base/_scope_filters.html.erb +0 -9
  100. data/config/initializers/will_paginate.rb +0 -28
  101. data/config/locales/brightcontent.en.yml +0 -10
  102. data/config/locales/brightcontent.nl.yml +0 -10
  103. data/lib/brightcontent/default_actions.rb +0 -28
  104. data/lib/brightcontent/pagination.rb +0 -28
  105. data/spec/features/scope_spec.rb +0 -27
@@ -1,45 +1,61 @@
1
- # Use this setup block to configure all options available in SimpleForm.
2
- SimpleForm.setup do |config|
3
- config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
4
- b.use :html5
5
- b.use :placeholder
6
- b.use :label
7
- b.wrapper :tag => 'div', :class => 'controls' do |ba|
8
- ba.use :input
9
- ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
10
- ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
1
+ inputs = %w[
2
+ CollectionSelectInput
3
+ DateTimeInput
4
+ FileInput
5
+ GroupedCollectionSelectInput
6
+ NumericInput
7
+ PasswordInput
8
+ RangeInput
9
+ StringInput
10
+ TextInput
11
+ ]
12
+
13
+ inputs.each do |input_type|
14
+ superclass = "SimpleForm::Inputs::#{input_type}".constantize
15
+
16
+ new_class = Class.new(superclass) do
17
+ def input_html_classes
18
+ super.push('form-control')
11
19
  end
12
20
  end
13
21
 
14
- config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
22
+ Object.const_set(input_type, new_class)
23
+ end
24
+
25
+ SimpleForm.setup do |config|
26
+ config.boolean_style = :nested
27
+
28
+ config.wrappers :bootstrap, tag: 'div', class: 'form-group', error_class: 'has-error',
29
+ defaults: { input_html: { class: 'default_class' } } do |b|
30
+
15
31
  b.use :html5
32
+ b.use :min_max
33
+ b.use :maxlength
16
34
  b.use :placeholder
35
+
36
+ b.optional :pattern
37
+ b.optional :readonly
38
+
17
39
  b.use :label
18
- b.wrapper :tag => 'div', :class => 'controls' do |input|
19
- input.wrapper :tag => 'div', :class => 'input-prepend' do |prepend|
20
- prepend.use :input
21
- end
22
- input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
23
- input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
40
+
41
+ b.wrapper tag: 'div', class: 'col-sm-10' do |ba|
42
+ ba.use :input
43
+ ba.use :hint, wrap_with: { tag: 'span', class: 'help-block' }
44
+ ba.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' }
24
45
  end
25
46
  end
26
47
 
27
- config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
48
+ config.wrappers :checkbox, tag: :div, class: "checkbox", error_class: "has-error" do |b|
28
49
  b.use :html5
29
- b.use :placeholder
30
- b.use :label
31
- b.wrapper :tag => 'div', :class => 'controls' do |input|
32
- input.wrapper :tag => 'div', :class => 'input-append' do |append|
33
- append.use :input
34
- end
35
- input.use :hint, :wrap_with => { :tag => 'span', :class => 'help-block' }
36
- input.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
50
+
51
+ b.wrapper tag: :label do |ba|
52
+ ba.use :input
53
+ ba.use :label_text
37
54
  end
55
+
56
+ b.use :hint, wrap_with: { tag: :p, class: "help-block" }
57
+ b.use :error, wrap_with: { tag: :span, class: "help-block text-danger" }
38
58
  end
39
59
 
40
- # Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
41
- # Check the Bootstrap docs (http://twitter.github.com/bootstrap)
42
- # to learn about the different styles for forms and inputs,
43
- # buttons and other elements.
44
60
  config.default_wrapper = :bootstrap
45
61
  end
@@ -0,0 +1,30 @@
1
+ en:
2
+ flash:
3
+ actions:
4
+ create:
5
+ notice: '%{resource_name} was successfully created.'
6
+ update:
7
+ notice: '%{resource_name} was successfully updated.'
8
+ destroy:
9
+ notice: '%{resource_name} was successfully destroyed.'
10
+ alert: '%{resource_name} could not be destroyed.'
11
+
12
+ brightcontent:
13
+ create_new: 'Create new %{model}'
14
+ edit: Edit
15
+ edit_model: 'Edit %{model}'
16
+ save_and_continue: Save and continue
17
+ delete: Delete
18
+ are_you_sure: Are you sure?
19
+ logout: Logout
20
+ hidden: Hidden
21
+ sign_in: Please sign in
22
+ editor_locale: ""
23
+
24
+ activerecord:
25
+ models:
26
+ brightcontent/admin_user: Admin
27
+ attributes:
28
+ brightcontent/admin_user:
29
+ password: Password
30
+ password_confirmation: Password confirmation
@@ -0,0 +1,30 @@
1
+ nl:
2
+ flash:
3
+ actions:
4
+ create:
5
+ notice: '%{resource_name} is succesvol aangemaakt.'
6
+ update:
7
+ notice: '%{resource_name} is succesvol geüpdatet.'
8
+ destroy:
9
+ notice: '%{resource_name} is succesvol verwijderd.'
10
+ alert: '%{resource_name} kon niet worden verwijderd.'
11
+
12
+ brightcontent:
13
+ create_new: '%{model} toevoegen'
14
+ edit: Wijzig
15
+ edit_model: '%{model} wijzigen'
16
+ save_and_continue: Opslaan en verder bewerken
17
+ delete: Verwijderen
18
+ are_you_sure: Zeker weten?
19
+ logout: Uitloggen
20
+ hidden: Verborgen
21
+ sign_in: Inloggen
22
+ editor_locale: "nl-NL"
23
+
24
+ activerecord:
25
+ models:
26
+ brightcontent/admin_user: Beheerder
27
+ attributes:
28
+ brightcontent/admin_user:
29
+ password: Wachtwoord
30
+ password_confirmation: Wachtwoord bevestiging
data/config/routes.rb CHANGED
@@ -5,5 +5,5 @@ Brightcontent::Engine.routes.draw do
5
5
  resources :admin_users
6
6
  resources :sessions, only: [:new, :create, :destroy]
7
7
 
8
- root to: "admin_users#index"
8
+ root to: "application#index"
9
9
  end
@@ -7,6 +7,6 @@ class CreateBrightcontentAdminUsers < ActiveRecord::Migration
7
7
  t.timestamps
8
8
  end
9
9
 
10
- Brightcontent::AdminUser.create!(:email => 'admin@example.com', :password => 'password')
10
+ Brightcontent::AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password')
11
11
  end
12
12
  end
@@ -0,0 +1,35 @@
1
+ module Brightcontent
2
+ module BaseControllerExt
3
+ module DefaultActions
4
+ def show
5
+ if request.format == :html
6
+ redirect_to action: :edit
7
+ else
8
+ show!
9
+ end
10
+ end
11
+
12
+ def create
13
+ create! { resource_redirect_path }
14
+ end
15
+
16
+ def update
17
+ update! { resource_redirect_path }
18
+ end
19
+
20
+ def destroy
21
+ destroy! { resource_index_path }
22
+ end
23
+
24
+ private
25
+
26
+ def resource_redirect_path
27
+ if params["commit_and_continue"].present?
28
+ resource_item_path
29
+ else
30
+ resource_index_path
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ module Brightcontent
2
+ module BaseControllerExt
3
+ module Fields
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ %w[list_fields filter_fields form_fields default_fields].each do |name|
8
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
9
+ def self.#{name}(*fields)
10
+ define_method(:#{name}) { fields.flatten }
11
+ end
12
+ helper_method :#{name}
13
+ RUBY
14
+ end
15
+ end
16
+
17
+ protected
18
+
19
+ def list_fields
20
+ default_fields
21
+ end
22
+
23
+ def filter_fields
24
+ []
25
+ end
26
+
27
+ def form_fields
28
+ default_fields
29
+ end
30
+
31
+ def default_fields
32
+ resource_class.brightcontent_columns - %w{id created_at updated_at password_digest}
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ require 'active_support/concern'
2
+
3
+ module Brightcontent
4
+ module BaseControllerExt
5
+ module Filtering
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ helper_method :ransack_search
10
+ end
11
+
12
+ def ransack_search
13
+ @_ransack_search ||= end_of_association_chain.ransack(params[:q])
14
+ end
15
+
16
+ def collection
17
+ @_collection ||= ransack_search.result(distinct: true)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ require 'active_support/concern'
2
+
3
+ module Brightcontent
4
+ module BaseControllerExt
5
+ module Pagination
6
+ extend ActiveSupport::Concern
7
+
8
+ module ClassMethods
9
+ def per_page_count
10
+ @per_page_count ||= 30
11
+ end
12
+
13
+ def per_page(number)
14
+ @per_page_count = number
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def end_of_association_chain
21
+ if action_name == "index" && self.class.per_page_count > 0
22
+ super.paginate(page: params[:page], per_page: self.class.per_page_count)
23
+ else
24
+ super
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,8 @@
1
+ module Brightcontent
2
+ module BaseControllerExt
3
+ autoload :DefaultActions, 'brightcontent/base_controller_ext/default_actions'
4
+ autoload :Pagination, 'brightcontent/base_controller_ext/pagination'
5
+ autoload :Fields, 'brightcontent/base_controller_ext/fields'
6
+ autoload :Filtering, 'brightcontent/base_controller_ext/filtering'
7
+ end
8
+ end
@@ -1,22 +1,32 @@
1
+ require "coffee_script"
2
+ require "bootstrap-sass"
3
+ require "bootstrap-wysihtml5-rails"
1
4
  require "inherited_resources"
2
- require "simple_form"
5
+ require "ransack"
3
6
  require "jquery-rails"
7
+ require "simple_form"
4
8
  require "will_paginate"
5
- require "bootstrap-wysihtml5-rails"
6
- require "has_scope"
7
- require "strong_parameters"
9
+ require "will_paginate-bootstrap"
8
10
 
9
11
  require "brightcontent/rails/routes"
10
12
  require "brightcontent/engine"
11
13
 
12
14
  module Brightcontent
13
-
14
- autoload :Pagination, 'brightcontent/pagination'
15
+ autoload :DefaultActions, 'brightcontent/default_actions'
16
+ autoload :ModelExtensions, 'brightcontent/model_extensions'
15
17
  autoload :PageMethods, 'brightcontent/page_methods'
18
+ autoload :Pagination, 'brightcontent/pagination'
19
+ autoload :Resource, 'brightcontent/resource'
20
+ autoload :Resources, 'brightcontent/resources'
16
21
  autoload :RoutesParser, 'brightcontent/routes_parser'
17
- autoload :DefaultActions, 'brightcontent/default_actions'
18
22
  autoload :StrongParamsFix, 'brightcontent/strong_params_fix'
19
- autoload :ModelExtensions, 'brightcontent/model_extensions'
23
+ autoload :ViewLookup, 'brightcontent/view_lookup'
24
+ autoload :BaseControllerExt, 'brightcontent/base_controller_ext'
25
+
26
+ mattr_accessor :locale
27
+
28
+ mattr_reader :extensions
29
+ @@extensions = %w{core}
20
30
 
21
31
  mattr_accessor :engine_resources
22
32
  @@engine_resources = %w{sessions admin_users}
@@ -27,10 +37,14 @@ module Brightcontent
27
37
  mattr_accessor :application_name
28
38
  @@application_name = "Brightcontent"
29
39
 
30
- # Default way to setup Brightcontent.
31
- # Run rails g brightcontent:install to create initializer
40
+ mattr_accessor :main_menu_count
41
+ @@main_menu_count = 6
42
+
32
43
  def self.setup
33
44
  yield self
34
45
  end
35
46
 
47
+ def self.register_extension(name)
48
+ @@extensions << name
49
+ end
36
50
  end
@@ -11,5 +11,11 @@ module Brightcontent
11
11
  include ModelExtensions
12
12
  end
13
13
  end
14
+
15
+ initializer "Set default locale from main app" do
16
+ ActiveSupport.on_load(:after_initialize) do
17
+ Brightcontent.locale ||= I18n.default_locale
18
+ end
19
+ end
14
20
  end
15
21
  end
@@ -0,0 +1,15 @@
1
+ require 'active_support/inflector'
2
+
3
+ module Brightcontent
4
+ Resource = Struct.new(:path) do
5
+ def klass
6
+ path.classify.constantize
7
+ rescue
8
+ "Brightcontent::#{path.classify}".constantize
9
+ end
10
+
11
+ def to_partial_path
12
+ "application/resource"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_support/core_ext/module/delegation'
2
+ require 'active_support/core_ext/object/blank'
3
+
4
+ module Brightcontent
5
+ Resources = Struct.new(:resources) do
6
+ include Enumerable
7
+ delegate :each, :==, to: :resources
8
+
9
+ def main_menu
10
+ take main_menu_count
11
+ end
12
+
13
+ def extra_menu
14
+ drop main_menu_count
15
+ end
16
+
17
+ def extra_menu?
18
+ resources.length > Brightcontent.main_menu_count
19
+ end
20
+
21
+ def main_menu_count
22
+ Brightcontent.main_menu_count - (extra_menu? ? 1 : 0)
23
+ end
24
+ end
25
+ end
@@ -2,28 +2,25 @@ require 'active_support/inflector'
2
2
 
3
3
  module Brightcontent
4
4
  class RoutesParser
5
-
6
- def initialize(routes_hash=nil, engine_resources=nil)
5
+ def initialize(routes_hash = nil, engine_resources = Brightcontent.engine_resources)
7
6
  @routes_hash = routes_hash
8
7
  @engine_resources = engine_resources
9
8
  end
10
9
 
11
10
  def resources
12
- (resource_names - engine_resources).map do |name|
13
- Resource.new(name)
14
- end
11
+ Resources.new(resources_array)
15
12
  end
16
13
 
17
- class Resource < Struct.new(:path)
18
- def klass
19
- path.classify.constantize
20
- rescue
21
- "Brightcontent::#{path.classify}".constantize
14
+ private
15
+
16
+ attr_reader :engine_resources
17
+
18
+ def resources_array
19
+ (resource_names - engine_resources).map do |name|
20
+ Resource.new(name)
22
21
  end
23
22
  end
24
23
 
25
- private
26
-
27
24
  def resource_names
28
25
  routes_hash.map do |route|
29
26
  next unless route && route[:controller] && route[:path_spec]
@@ -43,10 +40,5 @@ module Brightcontent
43
40
  }
44
41
  end
45
42
  end
46
-
47
- def engine_resources
48
- @engine_resources ||= Brightcontent.engine_resources
49
- end
50
-
51
43
  end
52
44
  end
@@ -0,0 +1,49 @@
1
+ require 'active_support/inflector'
2
+
3
+ module Brightcontent
4
+ module ViewLookup
5
+ class Abstract
6
+ attr_reader :options, :view_context
7
+
8
+ def initialize(view_context, options)
9
+ @view_context = view_context
10
+ @options = options
11
+ end
12
+
13
+ def call
14
+ render_by_field_name || render_by_type || render_default
15
+ end
16
+
17
+ private
18
+
19
+ def render_by_field_name
20
+ render("#{name}_#{options[:field]}", options)
21
+ end
22
+
23
+ def render_by_type
24
+ return unless field_type
25
+ render("brightcontent/base/#{name.pluralize}/#{field_type}", options)
26
+ end
27
+
28
+ def render_default
29
+ field_value
30
+ end
31
+
32
+ def field_type
33
+ raise NotImplementedError
34
+ end
35
+
36
+ def name
37
+ self.class.name.demodulize.underscore
38
+ end
39
+
40
+ def field_value
41
+ options[:item].send(options[:field])
42
+ end
43
+
44
+ def render(*args)
45
+ view_context.render_if_exists(*args)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,57 @@
1
+ module Brightcontent
2
+ module ViewLookup
3
+ class FilterField < Abstract
4
+ def render_default
5
+ raise "invalid filter field: #{options[:field]}" unless field_name
6
+ [
7
+ options[:form].label(:"#{field_name}_eq", options[:field].humanize),
8
+ options[:form].select(:"#{field_name}_eq", select_options, {include_blank: true}, class: "form-control input-sm")
9
+ ].join(" ").html_safe
10
+ end
11
+
12
+ def field_type
13
+ resource_class.columns_hash[options[:field]].try :type
14
+ end
15
+
16
+ private
17
+
18
+ def field?
19
+ resource_class.column_names.include? options[:field].to_s
20
+ end
21
+
22
+ def belongs_to_association?
23
+ association.try :belongs_to?
24
+ end
25
+
26
+ def field_name
27
+ if field?
28
+ options[:field]
29
+ elsif belongs_to_association?
30
+ association.foreign_key
31
+ end
32
+ end
33
+
34
+ def select_options
35
+ if field?
36
+ field_type == :boolean ? raw_options : raw_options.sort
37
+ elsif belongs_to_association?
38
+ association.klass.where(association.association_primary_key => raw_options).map do |record|
39
+ [record, record[association.association_primary_key]]
40
+ end
41
+ end
42
+ end
43
+
44
+ def raw_options
45
+ resource_class.uniq.pluck(field_name)
46
+ end
47
+
48
+ def association
49
+ resource_class.reflect_on_association options[:field].to_sym
50
+ end
51
+
52
+ def resource_class
53
+ view_context.send :resource_class
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,14 @@
1
+ module Brightcontent
2
+ module ViewLookup
3
+ class FormField < Abstract
4
+ def render_default
5
+ options[:form].input(options[:field].to_sym)
6
+ end
7
+
8
+ def field_type
9
+ column = options[:form].send(:find_attribute_column, options[:field])
10
+ options[:form].send(:default_input_type, options[:field], column, {})
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module Brightcontent
2
+ module ViewLookup
3
+ class ListField < Abstract
4
+ def render_default
5
+ view_context.strip_tags(field_value.to_s).truncate(50)
6
+ end
7
+
8
+ def field_type
9
+ options[:item].column_for_attribute(options[:field]).try(:type)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ module Brightcontent
2
+ module ViewLookup
3
+ autoload :Abstract, 'brightcontent/view_lookup/abstract'
4
+ autoload :FormField, 'brightcontent/view_lookup/form_field'
5
+ autoload :ListField, 'brightcontent/view_lookup/list_field'
6
+ autoload :FilterField, 'brightcontent/view_lookup/filter_field'
7
+ end
8
+ end
@@ -1,2 +1,2 @@
1
- class Brightcontent::<%= name.capitalize.pluralize %>Controller < Brightcontent::BaseController
1
+ class Brightcontent::<%= name.camelize.pluralize %>Controller < Brightcontent::BaseController
2
2
  end
@@ -2,7 +2,19 @@ Brightcontent.setup do |config|
2
2
  # The path where the admin interface should mount.
3
3
  config.path = "admin"
4
4
 
5
- # Name of the application which is displayed in header
6
- # Defaults to Rails application name
5
+ # Name of the application which is displayed in header.
6
+ # Defaults to Rails application name.
7
7
  # config.application_name = "Custom app name"
8
+
9
+ # Overwrite Brightcontent locale. Defaults to Rails locale.
10
+ # config.locale = "nl"
11
+
12
+ # Set the amount of menu items which are shown directly in the top bar.
13
+ # If there are more resources than this number, the remaining will be
14
+ # accumulated in a drop down menu.
15
+ # config.main_menu_count = 6
16
+
17
+ # The attachments model only allows images and pdf documents by default.
18
+ # Set to empty array to disable.
19
+ # config.attachment_content_types = [/\Aimage/, "application/pdf"]
8
20
  end
@@ -1,3 +1,3 @@
1
1
  class Brightcontent::BlogsController < Brightcontent::BaseController
2
- has_scope :featured, :type => :boolean
2
+ filter_fields %w[featured author]
3
3
  end
@@ -0,0 +1,7 @@
1
+ class Author < ActiveRecord::Base
2
+ has_many :blogs
3
+
4
+ def to_s
5
+ name
6
+ end
7
+ end
@@ -1,4 +1,5 @@
1
1
  class Blog < ActiveRecord::Base
2
- scope :featured, where(:featured => true)
2
+ belongs_to :author
3
3
  has_many :comments
4
+ scope :featured, ->{ where(:featured => true) }
4
5
  end