brightcontent 2.0.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/MIT-LICENSE +20 -0
- data/README.md +44 -0
- data/Rakefile +14 -0
- data/brightcontent.gemspec +21 -0
- data/core/.gitignore +9 -0
- data/core/Gemfile +17 -0
- data/core/Gemfile.lock +163 -0
- data/core/MIT-LICENSE +20 -0
- data/core/README.md +44 -0
- data/core/Rakefile +14 -0
- data/core/app/assets/images/brightcontent/.gitkeep +0 -0
- data/core/app/assets/images/brightcontent/glyphicons-halflings-white.png +0 -0
- data/core/app/assets/images/brightcontent/glyphicons-halflings.png +0 -0
- data/core/app/assets/javascripts/brightcontent/bootstrap.min.js +6 -0
- data/core/app/assets/javascripts/brightcontent/brightcontent.js +17 -0
- data/core/app/assets/javascripts/brightcontent/custom.js +1 -0
- data/core/app/assets/javascripts/brightcontent/main.js +3 -0
- data/core/app/assets/stylesheets/brightcontent/bootstrap-responsive.min.css +9 -0
- data/core/app/assets/stylesheets/brightcontent/bootstrap.min.css +9 -0
- data/core/app/assets/stylesheets/brightcontent/brightcontent.css +17 -0
- data/core/app/assets/stylesheets/brightcontent/custom.css +1 -0
- data/core/app/assets/stylesheets/brightcontent/main.css +44 -0
- data/core/app/controllers/brightcontent/admin_users_controller.rb +6 -0
- data/core/app/controllers/brightcontent/application_controller.rb +22 -0
- data/core/app/controllers/brightcontent/base_controller.rb +27 -0
- data/core/app/controllers/brightcontent/sessions_controller.rb +24 -0
- data/core/app/helpers/brightcontent/application_helper.rb +4 -0
- data/core/app/helpers/brightcontent/base_helper.rb +17 -0
- data/core/app/models/brightcontent/admin_user.rb +7 -0
- data/core/app/views/brightcontent/application/_menu.html.erb +3 -0
- data/core/app/views/brightcontent/application/_show_flash_names.html.erb +5 -0
- data/core/app/views/brightcontent/base/_form.html.erb +10 -0
- data/core/app/views/brightcontent/base/_list.html.erb +8 -0
- data/core/app/views/brightcontent/base/_list_actions.html.erb +2 -0
- data/core/app/views/brightcontent/base/edit.html.erb +3 -0
- data/core/app/views/brightcontent/base/index.html.erb +22 -0
- data/core/app/views/brightcontent/base/new.html.erb +3 -0
- data/core/app/views/brightcontent/sessions/new.html.erb +12 -0
- data/core/app/views/layouts/brightcontent/application.html.erb +53 -0
- data/core/brightcontent-core.gemspec +31 -0
- data/core/config/initializers/simple_form.rb +142 -0
- data/core/config/initializers/simple_form_bootstrap.rb +45 -0
- data/core/config/initializers/will_paginate.rb +28 -0
- data/core/config/routes.rb +9 -0
- data/core/db/migrate/20121206121725_create_brightcontent_admin_users.rb +12 -0
- data/core/lib/brightcontent/core/version.rb +5 -0
- data/core/lib/brightcontent/core.rb +32 -0
- data/core/lib/brightcontent/default_actions.rb +19 -0
- data/core/lib/brightcontent/engine.rb +9 -0
- data/core/lib/brightcontent/pagination.rb +24 -0
- data/core/lib/brightcontent/rails/routes.rb +16 -0
- data/core/lib/brightcontent/routes_parser.rb +38 -0
- data/core/lib/brightcontent-core.rb +1 -0
- data/core/lib/generators/brightcontent/install_generator.rb +34 -0
- data/core/lib/generators/brightcontent/resource_generator.rb +22 -0
- data/core/lib/generators/brightcontent/templates/brightcontent_controller.rb +2 -0
- data/core/lib/generators/brightcontent/templates/initializer.rb +8 -0
- data/core/script/rails +8 -0
- data/core/spec/dummy/README.rdoc +261 -0
- data/core/spec/dummy/Rakefile +7 -0
- data/core/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/core/spec/dummy/app/assets/javascripts/brightcontent/custom.js +1 -0
- data/core/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/core/spec/dummy/app/assets/stylesheets/brightcontent/custom.css +1 -0
- data/core/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/core/spec/dummy/app/controllers/brightcontent/blogs_controller.rb +2 -0
- data/core/spec/dummy/app/controllers/pages_controller.rb +8 -0
- data/core/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/core/spec/dummy/app/mailers/.gitkeep +0 -0
- data/core/spec/dummy/app/models/.gitkeep +0 -0
- data/core/spec/dummy/app/models/blog.rb +3 -0
- data/core/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/core/spec/dummy/app/views/pages/index.html.erb +1 -0
- data/core/spec/dummy/config/application.rb +59 -0
- data/core/spec/dummy/config/boot.rb +10 -0
- data/core/spec/dummy/config/database.yml +25 -0
- data/core/spec/dummy/config/environment.rb +5 -0
- data/core/spec/dummy/config/environments/development.rb +37 -0
- data/core/spec/dummy/config/environments/production.rb +67 -0
- data/core/spec/dummy/config/environments/test.rb +37 -0
- data/core/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/core/spec/dummy/config/initializers/brightcontent.rb +3 -0
- data/core/spec/dummy/config/initializers/inflections.rb +15 -0
- data/core/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/core/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/core/spec/dummy/config/initializers/session_store.rb +8 -0
- data/core/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/core/spec/dummy/config/locales/en.yml +5 -0
- data/core/spec/dummy/config/routes.rb +7 -0
- data/core/spec/dummy/config.ru +4 -0
- data/core/spec/dummy/db/migrate/20121206225720_create_blogs.rb +10 -0
- data/core/spec/dummy/db/schema.rb +30 -0
- data/core/spec/dummy/lib/assets/.gitkeep +0 -0
- data/core/spec/dummy/public/404.html +26 -0
- data/core/spec/dummy/public/422.html +26 -0
- data/core/spec/dummy/public/500.html +25 -0
- data/core/spec/dummy/public/favicon.ico +0 -0
- data/core/spec/dummy/script/rails +6 -0
- data/core/spec/factories.rb +16 -0
- data/core/spec/features/login_spec.rb +29 -0
- data/core/spec/features/menu_spec.rb +27 -0
- data/core/spec/features/resources_form_spec.rb +51 -0
- data/core/spec/features/resources_index_spec.rb +50 -0
- data/core/spec/lib/brightcontent/routes_parser_spec.rb +34 -0
- data/core/spec/spec_helper.rb +18 -0
- data/core/spec/support/acceptance_helper.rb +8 -0
- data/lib/brightcontent.rb +2 -0
- data/lib/tasks/release.rake +0 -0
- data/lib/tasks/rspec.rake +5 -0
- data/pages/.gitignore +9 -0
- data/pages/Gemfile +5 -0
- data/pages/Gemfile.lock +173 -0
- data/pages/MIT-LICENSE +20 -0
- data/pages/README.md +35 -0
- data/pages/Rakefile +14 -0
- data/pages/app/assets/images/brightcontent/.gitkeep +0 -0
- data/pages/app/controllers/brightcontent/pages_controller.rb +16 -0
- data/pages/app/helpers/brightcontent/pages_helper.rb +13 -0
- data/pages/app/models/brightcontent/page.rb +27 -0
- data/pages/app/views/brightcontent/pages/_form_field_parent_id.html.erb +1 -0
- data/pages/app/views/brightcontent/pages/_list_field_name.html.erb +1 -0
- data/pages/brightcontent-pages.gemspec +26 -0
- data/pages/config/routes.rb +3 -0
- data/pages/db/migrate/20121207132810_create_brightcontent_pages.rb +16 -0
- data/pages/lib/brightcontent/pages/engine.rb +14 -0
- data/pages/lib/brightcontent/pages/methods.rb +9 -0
- data/pages/lib/brightcontent/pages/version.rb +5 -0
- data/pages/lib/brightcontent/pages.rb +10 -0
- data/pages/lib/brightcontent-pages.rb +1 -0
- data/pages/lib/generators/brightcontent/pages/install_generator.rb +15 -0
- data/pages/script/rails +8 -0
- data/pages/spec/dummy/README.rdoc +261 -0
- data/pages/spec/dummy/Rakefile +7 -0
- data/pages/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/pages/spec/dummy/app/assets/javascripts/brightcontent/custom.js +1 -0
- data/pages/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/pages/spec/dummy/app/assets/stylesheets/brightcontent/custom.css +1 -0
- data/pages/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/pages/spec/dummy/app/controllers/brightcontent/blogs_controller.rb +2 -0
- data/pages/spec/dummy/app/controllers/pages_controller.rb +8 -0
- data/pages/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/pages/spec/dummy/app/mailers/.gitkeep +0 -0
- data/pages/spec/dummy/app/models/.gitkeep +0 -0
- data/pages/spec/dummy/app/models/blog.rb +3 -0
- data/pages/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/pages/spec/dummy/app/views/pages/index.html.erb +1 -0
- data/pages/spec/dummy/config/application.rb +59 -0
- data/pages/spec/dummy/config/boot.rb +10 -0
- data/pages/spec/dummy/config/database.yml +25 -0
- data/pages/spec/dummy/config/environment.rb +5 -0
- data/pages/spec/dummy/config/environments/development.rb +37 -0
- data/pages/spec/dummy/config/environments/production.rb +67 -0
- data/pages/spec/dummy/config/environments/test.rb +37 -0
- data/pages/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/pages/spec/dummy/config/initializers/brightcontent.rb +3 -0
- data/pages/spec/dummy/config/initializers/inflections.rb +15 -0
- data/pages/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/pages/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/pages/spec/dummy/config/initializers/session_store.rb +8 -0
- data/pages/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/pages/spec/dummy/config/locales/en.yml +5 -0
- data/pages/spec/dummy/config/routes.rb +6 -0
- data/pages/spec/dummy/config.ru +4 -0
- data/pages/spec/dummy/db/schema.rb +44 -0
- data/pages/spec/dummy/lib/assets/.gitkeep +0 -0
- data/pages/spec/dummy/public/404.html +26 -0
- data/pages/spec/dummy/public/422.html +26 -0
- data/pages/spec/dummy/public/500.html +25 -0
- data/pages/spec/dummy/public/favicon.ico +0 -0
- data/pages/spec/dummy/script/rails +6 -0
- data/pages/spec/factories.rb +16 -0
- data/pages/spec/features/menu_spec.rb +16 -0
- data/pages/spec/features/pages_spec.rb +18 -0
- data/pages/spec/models/brightcontent/page_spec.rb +49 -0
- data/pages/spec/spec_helper.rb +18 -0
- data/pages/spec/support/acceptance_helper.rb +8 -0
- metadata +253 -0
@@ -0,0 +1,142 @@
|
|
1
|
+
# Use this setup block to configure all options available in SimpleForm.
|
2
|
+
SimpleForm.setup do |config|
|
3
|
+
# Wrappers are used by the form builder to generate a
|
4
|
+
# complete input. You can remove any component from the
|
5
|
+
# wrapper, change the order or even add your own to the
|
6
|
+
# stack. The options given below are used to wrap the
|
7
|
+
# whole input.
|
8
|
+
config.wrappers :default, :class => :input,
|
9
|
+
:hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
|
10
|
+
## Extensions enabled by default
|
11
|
+
# Any of these extensions can be disabled for a
|
12
|
+
# given input by passing: `f.input EXTENSION_NAME => false`.
|
13
|
+
# You can make any of these extensions optional by
|
14
|
+
# renaming `b.use` to `b.optional`.
|
15
|
+
|
16
|
+
# Determines whether to use HTML5 (:email, :url, ...)
|
17
|
+
# and required attributes
|
18
|
+
b.use :html5
|
19
|
+
|
20
|
+
# Calculates placeholders automatically from I18n
|
21
|
+
# You can also pass a string as f.input :placeholder => "Placeholder"
|
22
|
+
b.use :placeholder
|
23
|
+
|
24
|
+
## Optional extensions
|
25
|
+
# They are disabled unless you pass `f.input EXTENSION_NAME => :lookup`
|
26
|
+
# to the input. If so, they will retrieve the values from the model
|
27
|
+
# if any exists. If you want to enable the lookup for any of those
|
28
|
+
# extensions by default, you can change `b.optional` to `b.use`.
|
29
|
+
|
30
|
+
# Calculates maxlength from length validations for string inputs
|
31
|
+
b.optional :maxlength
|
32
|
+
|
33
|
+
# Calculates pattern from format validations for string inputs
|
34
|
+
b.optional :pattern
|
35
|
+
|
36
|
+
# Calculates min and max from length validations for numeric inputs
|
37
|
+
b.optional :min_max
|
38
|
+
|
39
|
+
# Calculates readonly automatically from readonly attributes
|
40
|
+
b.optional :readonly
|
41
|
+
|
42
|
+
## Inputs
|
43
|
+
b.use :label_input
|
44
|
+
b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
|
45
|
+
b.use :error, :wrap_with => { :tag => :span, :class => :error }
|
46
|
+
end
|
47
|
+
|
48
|
+
# The default wrapper to be used by the FormBuilder.
|
49
|
+
config.default_wrapper = :default
|
50
|
+
|
51
|
+
# Define the way to render check boxes / radio buttons with labels.
|
52
|
+
# Defaults to :nested for bootstrap config.
|
53
|
+
# :inline => input + label
|
54
|
+
# :nested => label > input
|
55
|
+
config.boolean_style = :nested
|
56
|
+
|
57
|
+
# Default class for buttons
|
58
|
+
config.button_class = 'btn'
|
59
|
+
|
60
|
+
# Method used to tidy up errors. Specify any Rails Array method.
|
61
|
+
# :first lists the first message for each field.
|
62
|
+
# Use :to_sentence to list all errors for each field.
|
63
|
+
# config.error_method = :first
|
64
|
+
|
65
|
+
# Default tag used for error notification helper.
|
66
|
+
config.error_notification_tag = :div
|
67
|
+
|
68
|
+
# CSS class to add for error notification helper.
|
69
|
+
config.error_notification_class = 'alert alert-error'
|
70
|
+
|
71
|
+
# ID to add for error notification helper.
|
72
|
+
# config.error_notification_id = nil
|
73
|
+
|
74
|
+
# Series of attempts to detect a default label method for collection.
|
75
|
+
# config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
|
76
|
+
|
77
|
+
# Series of attempts to detect a default value method for collection.
|
78
|
+
# config.collection_value_methods = [ :id, :to_s ]
|
79
|
+
|
80
|
+
# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
|
81
|
+
# config.collection_wrapper_tag = nil
|
82
|
+
|
83
|
+
# You can define the class to use on all collection wrappers. Defaulting to none.
|
84
|
+
# config.collection_wrapper_class = nil
|
85
|
+
|
86
|
+
# You can wrap each item in a collection of radio/check boxes with a tag,
|
87
|
+
# defaulting to :span. Please note that when using :boolean_style = :nested,
|
88
|
+
# SimpleForm will force this option to be a label.
|
89
|
+
# config.item_wrapper_tag = :span
|
90
|
+
|
91
|
+
# You can define a class to use in all item wrappers. Defaulting to none.
|
92
|
+
# config.item_wrapper_class = nil
|
93
|
+
|
94
|
+
# How the label text should be generated altogether with the required text.
|
95
|
+
# config.label_text = lambda { |label, required| "#{required} #{label}" }
|
96
|
+
|
97
|
+
# You can define the class to use on all labels. Default is nil.
|
98
|
+
config.label_class = 'control-label'
|
99
|
+
|
100
|
+
# You can define the class to use on all forms. Default is simple_form.
|
101
|
+
config.form_class = 'form-horizontal'
|
102
|
+
|
103
|
+
# You can define which elements should obtain additional classes
|
104
|
+
# config.generate_additional_classes_for = [:wrapper, :label, :input]
|
105
|
+
|
106
|
+
# Whether attributes are required by default (or not). Default is true.
|
107
|
+
# config.required_by_default = true
|
108
|
+
|
109
|
+
# Tell browsers whether to use default HTML5 validations (novalidate option).
|
110
|
+
# Default is enabled.
|
111
|
+
config.browser_validations = false
|
112
|
+
|
113
|
+
# Collection of methods to detect if a file type was given.
|
114
|
+
# config.file_methods = [ :mounted_as, :file?, :public_filename ]
|
115
|
+
|
116
|
+
# Custom mappings for input types. This should be a hash containing a regexp
|
117
|
+
# to match as key, and the input type that will be used when the field name
|
118
|
+
# matches the regexp as value.
|
119
|
+
# config.input_mappings = { /count/ => :integer }
|
120
|
+
|
121
|
+
# Custom wrappers for input types. This should be a hash containing an input
|
122
|
+
# type as key and the wrapper that will be used for all inputs with specified type.
|
123
|
+
# config.wrapper_mappings = { :string => :prepend }
|
124
|
+
|
125
|
+
# Default priority for time_zone inputs.
|
126
|
+
# config.time_zone_priority = nil
|
127
|
+
|
128
|
+
# Default priority for country inputs.
|
129
|
+
# config.country_priority = nil
|
130
|
+
|
131
|
+
# Default size for text inputs.
|
132
|
+
# config.default_input_size = 50
|
133
|
+
|
134
|
+
# When false, do not use translations for labels.
|
135
|
+
# config.translate_labels = true
|
136
|
+
|
137
|
+
# Automatically discover new inputs in Rails' autoload path.
|
138
|
+
# config.inputs_discovery = true
|
139
|
+
|
140
|
+
# Cache SimpleForm inputs discovery
|
141
|
+
config.cache_discovery = !Rails.env.development?
|
142
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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' }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
config.wrappers :prepend, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
|
15
|
+
b.use :html5
|
16
|
+
b.use :placeholder
|
17
|
+
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' }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
config.wrappers :append, :tag => 'div', :class => "control-group", :error_class => 'error' do |b|
|
28
|
+
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' }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
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
|
+
config.default_wrapper = :bootstrap
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module WillPaginate
|
2
|
+
module ActionView
|
3
|
+
def will_paginate(collection = nil, options = {})
|
4
|
+
options[:renderer] ||= BootstrapLinkRenderer
|
5
|
+
super.try :html_safe
|
6
|
+
end
|
7
|
+
|
8
|
+
class BootstrapLinkRenderer < LinkRenderer
|
9
|
+
protected
|
10
|
+
|
11
|
+
def html_container(html)
|
12
|
+
tag :div, tag(:ul, html), container_attributes
|
13
|
+
end
|
14
|
+
|
15
|
+
def page_number(page)
|
16
|
+
tag :li, link(page, page, :rel => rel_value(page)), :class => ('active' if page == current_page)
|
17
|
+
end
|
18
|
+
|
19
|
+
def previous_or_next_page(page, text, classname)
|
20
|
+
tag :li, link(text, page || '#'), :class => [classname[0..3], classname, ('disabled' unless page)].join(' ')
|
21
|
+
end
|
22
|
+
|
23
|
+
def gap
|
24
|
+
tag :li, link(super, '#'), :class => 'disabled'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateBrightcontentAdminUsers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :brightcontent_admin_users do |t|
|
4
|
+
t.string :email
|
5
|
+
t.string :password_digest
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
Brightcontent::AdminUser.create!(:email => 'admin@example.com', :password => 'password')
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "inherited_resources"
|
2
|
+
require "simple_form"
|
3
|
+
require "jquery-rails"
|
4
|
+
require "will_paginate"
|
5
|
+
require "bootstrap-wysihtml5-rails"
|
6
|
+
|
7
|
+
require "brightcontent/rails/routes"
|
8
|
+
require "brightcontent/engine"
|
9
|
+
|
10
|
+
module Brightcontent
|
11
|
+
|
12
|
+
autoload :Pagination, 'brightcontent/pagination'
|
13
|
+
autoload :PageMethods, 'brightcontent/page_methods'
|
14
|
+
autoload :RoutesParser, 'brightcontent/routes_parser'
|
15
|
+
autoload :DefaultActions, 'brightcontent/default_actions'
|
16
|
+
|
17
|
+
mattr_accessor :engine_resources
|
18
|
+
@@engine_resources = %w{sessions admin_users}
|
19
|
+
|
20
|
+
mattr_accessor :path
|
21
|
+
@@path = "admin"
|
22
|
+
|
23
|
+
mattr_accessor :application_name
|
24
|
+
@@application_name = "Brightcontent"
|
25
|
+
|
26
|
+
# Default way to setup Brightcontent.
|
27
|
+
# Run rails g brightcontent:install to create initializer
|
28
|
+
def self.setup
|
29
|
+
yield self
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Brightcontent
|
2
|
+
module DefaultActions
|
3
|
+
def show
|
4
|
+
redirect_to action: :edit
|
5
|
+
end
|
6
|
+
|
7
|
+
def create
|
8
|
+
create! { polymorphic_url(resource_class) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def update
|
12
|
+
update! { polymorphic_url(resource_class) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def destroy
|
16
|
+
destroy! { polymorphic_url(resource_class) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Brightcontent
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace Brightcontent
|
4
|
+
|
5
|
+
initializer "Brightcontent precompile hook", :group => :all do |app|
|
6
|
+
app.config.assets.precompile += ['brightcontent/brightcontent.js', 'brightcontent/brightcontent.css']
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Brightcontent
|
4
|
+
module Pagination
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def per_page(number)
|
9
|
+
@per_page_count = number
|
10
|
+
end
|
11
|
+
|
12
|
+
def per_page_count
|
13
|
+
@per_page_count || 30
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def end_of_association_chain
|
20
|
+
super.paginate(page: params[:page], per_page: self.class.per_page_count)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActionDispatch::Routing
|
2
|
+
class Mapper
|
3
|
+
def brightcontent_resources(&block)
|
4
|
+
define_user_resources(block) if block_given?
|
5
|
+
mount Brightcontent::Engine => Brightcontent.path
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def define_user_resources(block)
|
11
|
+
Brightcontent::Engine.routes.draw do
|
12
|
+
instance_eval &block
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
module Brightcontent
|
4
|
+
class RoutesParser
|
5
|
+
|
6
|
+
def self.parse(routes_hash=nil, engine_resources=nil)
|
7
|
+
new(routes_hash, engine_resources).user_resource
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(routes_hash=nil, engine_resources=nil)
|
11
|
+
@routes_hash = routes_hash
|
12
|
+
@engine_resources = engine_resources
|
13
|
+
end
|
14
|
+
|
15
|
+
def user_resource
|
16
|
+
resource_names - engine_resources
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def resource_names
|
22
|
+
routes_hash.map do |route|
|
23
|
+
if route && route[:action] == "index"
|
24
|
+
route[:controller].match(/brightcontent\/(.+)/)[1]
|
25
|
+
end
|
26
|
+
end.compact
|
27
|
+
end
|
28
|
+
|
29
|
+
def routes_hash
|
30
|
+
@routes_hash ||= Engine.routes.routes.map(&:defaults)
|
31
|
+
end
|
32
|
+
|
33
|
+
def engine_resources
|
34
|
+
@engine_resources ||= Brightcontent.engine_resources
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'brightcontent/core'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Brightcontent
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
|
6
|
+
desc "Creates a Brightcontent initializer, copy migrations, edit routes file"
|
7
|
+
|
8
|
+
def copy_initializer
|
9
|
+
template "initializer.rb", "config/initializers/brightcontent.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
def copy_migrations
|
13
|
+
rake "brightcontent:install:migrations"
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_routes
|
17
|
+
route "brightcontent_resources do\n" \
|
18
|
+
" #resources :vacancies #for example\n" \
|
19
|
+
" end"
|
20
|
+
end
|
21
|
+
|
22
|
+
def copy_custom_assets
|
23
|
+
copy_file "../../../../app/assets/stylesheets/brightcontent/custom.css", "app/assets/stylesheets/brightcontent/custom.css"
|
24
|
+
copy_file "../../../../app/assets/javascripts/brightcontent/custom.js", "app/assets/javascripts/brightcontent/custom.js"
|
25
|
+
end
|
26
|
+
|
27
|
+
def setup_directory
|
28
|
+
empty_directory "app/controllers/brightcontent"
|
29
|
+
empty_directory "app/views/brightcontent"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Brightcontent
|
2
|
+
module Generators
|
3
|
+
class ResourceGenerator < Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
|
6
|
+
desc "Creates Brightcontent controller, route and empty views dir"
|
7
|
+
|
8
|
+
def generate_controller
|
9
|
+
template "brightcontent_controller.rb", "app/controllers/brightcontent/#{@name.pluralize.underscore}_controller.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_views_directory
|
13
|
+
empty_directory "app/views/brightcontent/#{name.pluralize.underscore}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_route
|
17
|
+
inject_into_file 'config/routes.rb', "\n resources :#{name.pluralize.underscore}", { :after => "brightcontent_resources do" }
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/core/script/rails
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/brightcontent/engine', __FILE__)
|
6
|
+
|
7
|
+
require 'rails/all'
|
8
|
+
require 'rails/engine/commands'
|