brightcontent-core 2.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/.gitignore +9 -0
  2. data/Gemfile +17 -0
  3. data/Gemfile.lock +163 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +44 -0
  6. data/Rakefile +14 -0
  7. data/app/assets/images/brightcontent/.gitkeep +0 -0
  8. data/app/assets/images/brightcontent/glyphicons-halflings-white.png +0 -0
  9. data/app/assets/images/brightcontent/glyphicons-halflings.png +0 -0
  10. data/app/assets/javascripts/brightcontent/bootstrap.min.js +6 -0
  11. data/app/assets/javascripts/brightcontent/brightcontent.js +17 -0
  12. data/app/assets/javascripts/brightcontent/custom.js +1 -0
  13. data/app/assets/javascripts/brightcontent/main.js +3 -0
  14. data/app/assets/stylesheets/brightcontent/bootstrap-responsive.min.css +9 -0
  15. data/app/assets/stylesheets/brightcontent/bootstrap.min.css +9 -0
  16. data/app/assets/stylesheets/brightcontent/brightcontent.css +17 -0
  17. data/app/assets/stylesheets/brightcontent/custom.css +1 -0
  18. data/app/assets/stylesheets/brightcontent/main.css +44 -0
  19. data/app/controllers/brightcontent/admin_users_controller.rb +6 -0
  20. data/app/controllers/brightcontent/application_controller.rb +22 -0
  21. data/app/controllers/brightcontent/base_controller.rb +27 -0
  22. data/app/controllers/brightcontent/sessions_controller.rb +24 -0
  23. data/app/helpers/brightcontent/application_helper.rb +4 -0
  24. data/app/helpers/brightcontent/base_helper.rb +17 -0
  25. data/app/models/brightcontent/admin_user.rb +7 -0
  26. data/app/views/brightcontent/application/_menu.html.erb +3 -0
  27. data/app/views/brightcontent/application/_show_flash_names.html.erb +5 -0
  28. data/app/views/brightcontent/base/_form.html.erb +10 -0
  29. data/app/views/brightcontent/base/_list.html.erb +8 -0
  30. data/app/views/brightcontent/base/_list_actions.html.erb +2 -0
  31. data/app/views/brightcontent/base/edit.html.erb +3 -0
  32. data/app/views/brightcontent/base/index.html.erb +22 -0
  33. data/app/views/brightcontent/base/new.html.erb +3 -0
  34. data/app/views/brightcontent/sessions/new.html.erb +12 -0
  35. data/app/views/layouts/brightcontent/application.html.erb +53 -0
  36. data/brightcontent-core.gemspec +31 -0
  37. data/config/initializers/simple_form.rb +142 -0
  38. data/config/initializers/simple_form_bootstrap.rb +45 -0
  39. data/config/initializers/will_paginate.rb +28 -0
  40. data/config/routes.rb +9 -0
  41. data/db/migrate/20121206121725_create_brightcontent_admin_users.rb +12 -0
  42. data/lib/brightcontent-core.rb +1 -0
  43. data/lib/brightcontent/core.rb +32 -0
  44. data/lib/brightcontent/core/version.rb +5 -0
  45. data/lib/brightcontent/default_actions.rb +19 -0
  46. data/lib/brightcontent/engine.rb +9 -0
  47. data/lib/brightcontent/pagination.rb +24 -0
  48. data/lib/brightcontent/rails/routes.rb +16 -0
  49. data/lib/brightcontent/routes_parser.rb +38 -0
  50. data/lib/generators/brightcontent/install_generator.rb +34 -0
  51. data/lib/generators/brightcontent/resource_generator.rb +22 -0
  52. data/lib/generators/brightcontent/templates/brightcontent_controller.rb +2 -0
  53. data/lib/generators/brightcontent/templates/initializer.rb +8 -0
  54. data/script/rails +8 -0
  55. data/spec/dummy/README.rdoc +261 -0
  56. data/spec/dummy/Rakefile +7 -0
  57. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  58. data/spec/dummy/app/assets/javascripts/brightcontent/custom.js +1 -0
  59. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  60. data/spec/dummy/app/assets/stylesheets/brightcontent/custom.css +1 -0
  61. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  62. data/spec/dummy/app/controllers/brightcontent/blogs_controller.rb +2 -0
  63. data/spec/dummy/app/controllers/pages_controller.rb +8 -0
  64. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  65. data/spec/dummy/app/mailers/.gitkeep +0 -0
  66. data/spec/dummy/app/models/.gitkeep +0 -0
  67. data/spec/dummy/app/models/blog.rb +3 -0
  68. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  69. data/spec/dummy/app/views/pages/index.html.erb +1 -0
  70. data/spec/dummy/config.ru +4 -0
  71. data/spec/dummy/config/application.rb +59 -0
  72. data/spec/dummy/config/boot.rb +10 -0
  73. data/spec/dummy/config/database.yml +25 -0
  74. data/spec/dummy/config/environment.rb +5 -0
  75. data/spec/dummy/config/environments/development.rb +37 -0
  76. data/spec/dummy/config/environments/production.rb +67 -0
  77. data/spec/dummy/config/environments/test.rb +37 -0
  78. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  79. data/spec/dummy/config/initializers/brightcontent.rb +3 -0
  80. data/spec/dummy/config/initializers/inflections.rb +15 -0
  81. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  82. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  83. data/spec/dummy/config/initializers/session_store.rb +8 -0
  84. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  85. data/spec/dummy/config/locales/en.yml +5 -0
  86. data/spec/dummy/config/routes.rb +7 -0
  87. data/spec/dummy/db/migrate/20121206225720_create_blogs.rb +10 -0
  88. data/spec/dummy/db/schema.rb +30 -0
  89. data/spec/dummy/lib/assets/.gitkeep +0 -0
  90. data/spec/dummy/public/404.html +26 -0
  91. data/spec/dummy/public/422.html +26 -0
  92. data/spec/dummy/public/500.html +25 -0
  93. data/spec/dummy/public/favicon.ico +0 -0
  94. data/spec/dummy/script/rails +6 -0
  95. data/spec/factories.rb +16 -0
  96. data/spec/features/login_spec.rb +29 -0
  97. data/spec/features/menu_spec.rb +27 -0
  98. data/spec/features/resources_form_spec.rb +51 -0
  99. data/spec/features/resources_index_spec.rb +50 -0
  100. data/spec/lib/brightcontent/routes_parser_spec.rb +34 -0
  101. data/spec/spec_helper.rb +18 -0
  102. data/spec/support/acceptance_helper.rb +8 -0
  103. metadata +389 -0
@@ -0,0 +1,24 @@
1
+ module Brightcontent
2
+ class SessionsController < ApplicationController
3
+ skip_before_filter :authorize
4
+
5
+ def new
6
+ end
7
+
8
+ def create
9
+ user = AdminUser.find_by_email(params[:email])
10
+ if user && user.authenticate(params[:password])
11
+ session[:brightcontent_user_id] = user.id
12
+ redirect_to root_url
13
+ else
14
+ flash.now.alert = "Email or password is invalid"
15
+ render :new
16
+ end
17
+ end
18
+
19
+ def destroy
20
+ session[:brightcontent_user_id] = nil
21
+ redirect_to root_url
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ module Brightcontent
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,17 @@
1
+ module Brightcontent
2
+ module BaseHelper
3
+ def render_list_field(item, field)
4
+ render_if_exists("list_field_#{field}", item: item) || item.send(field).truncate(50)
5
+ end
6
+
7
+ def render_form_field(form, field)
8
+ render_if_exists("form_field_#{field}", form: form, item: form.object) || form.input(field.to_sym)
9
+ end
10
+
11
+ def render_if_exists(*args)
12
+ render *args
13
+ rescue ActionView::MissingTemplate
14
+ nil
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module Brightcontent
2
+ class AdminUser < ActiveRecord::Base
3
+ has_secure_password
4
+ attr_accessible :email, :password, :password_confirmation
5
+ validates_uniqueness_of :email
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ <% resource_paths.each do |resource_path| %>
2
+ <li><%= link_to resource_path.titleize, root_path + resource_path %></li>
3
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% flash.each do |key,value| %>
2
+ <div class="flash <%= key.to_s%>">
3
+ <%= value %>
4
+ </div>
5
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <%= simple_form_for resource do |form| %>
2
+ <%= form.error_notification %>
3
+
4
+ <div class="form-inputs">
5
+ <% form_fields.each do |form_field| %>
6
+ <%= render_form_field(form, form_field) %>
7
+ <% end %>
8
+ </div>
9
+ <%= form.button :submit, class: "btn btn-primary" %>
10
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <% collection.each do |item| %>
2
+ <%= content_tag_for :tr, item do %>
3
+ <% list_fields.each do |field| %>
4
+ <td><%= render_list_field(item, field) %></td>
5
+ <% end %>
6
+ <td class="list-actions"><%= render "list_actions", item: item %></td>
7
+ <% end %>
8
+ <% end %>
@@ -0,0 +1,2 @@
1
+ <%= link_to "Edit", polymorphic_url(item, action: :edit), class: "btn btn-mini btn-primary" %>
2
+ <%= link_to "Delete", polymorphic_url(item), class: "btn btn-mini", confirm: 'Are you sure?', method: :delete %>
@@ -0,0 +1,3 @@
1
+ <h1>Edit <%= resource_instance_name.to_s %></h1>
2
+
3
+ <%= render "form" %>
@@ -0,0 +1,22 @@
1
+ <div id="overview">
2
+
3
+ <%= link_to "Create new #{resource_instance_name.to_s.humanize}", polymorphic_url(resource_class, action: :new), class: "btn btn-primary btn-right" %>
4
+ <h1><%= resource_collection_name.to_s.humanize %></h1>
5
+
6
+ <table class="table table-hover">
7
+ <thead>
8
+ <tr>
9
+ <% list_fields.each do |list_field| %>
10
+ <th><%= list_field.humanize %></th>
11
+ <% end %>
12
+ <th></th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <%= render "list", collection: collection, list_fields: list_fields %>
17
+ </tbody>
18
+ </table>
19
+
20
+ <%= will_paginate collection %>
21
+
22
+ </div>
@@ -0,0 +1,3 @@
1
+ <h1>Create new <%= resource_instance_name.to_s %></h1>
2
+
3
+ <%= render "form" %>
@@ -0,0 +1,12 @@
1
+ <%= form_tag sessions_path, class: "form-signin" do %>
2
+ <h2>Please sign in</h2>
3
+ <div class="field">
4
+ <%= label_tag :email %>
5
+ <%= text_field_tag :email, params[:email] %>
6
+ </div>
7
+ <div class="field">
8
+ <%= label_tag :password %>
9
+ <%= password_field_tag :password %>
10
+ </div>
11
+ <%= submit_tag "Login", class: "btn btn-large btn-primary" %>
12
+ <% end %>
@@ -0,0 +1,53 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Brightcontent</title>
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <%= stylesheet_link_tag "brightcontent/brightcontent", :media => "all" %>
7
+ <%= javascript_include_tag "brightcontent/brightcontent" %>
8
+ <%= csrf_meta_tags %>
9
+ <!--[if lt IE 9]>
10
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
11
+ <![endif]-->
12
+ </head>
13
+ <body>
14
+
15
+
16
+ <% if current_user %>
17
+ <div class="navbar">
18
+ <div class="navbar-inner">
19
+ <div class="container">
20
+ <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
21
+ <span class="icon-bar"></span>
22
+ <span class="icon-bar"></span>
23
+ <span class="icon-bar"></span>
24
+ </a>
25
+ <%= link_to Brightcontent.application_name, root_path, class: "brand" %>
26
+ <div class="nav-collapse collapse">
27
+ <ul class="nav" id="menu">
28
+ <%= render "menu" %>
29
+ </ul>
30
+ <ul class="nav pull-right">
31
+ <li class="dropdown">
32
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown"><%= current_user.email %><b class="caret"></b></a>
33
+ <ul class="dropdown-menu">
34
+ <li><%= link_to "Admins", admin_users_path %></li>
35
+ <li><%= link_to "Logout", logout_path %></li>
36
+ <ul>
37
+ </li>
38
+ </ul>
39
+ </div>
40
+ </div>
41
+ </div>
42
+ </div>
43
+ <% end %>
44
+
45
+ <div class="container box">
46
+ <%= render "brightcontent/application/show_flash_names" %>
47
+ <%= yield %>
48
+ </div>
49
+
50
+ </div>
51
+
52
+ </body>
53
+ </html>
@@ -0,0 +1,31 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require "brightcontent/core/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "brightcontent-core"
7
+ s.version = Brightcontent::Core::VERSION
8
+ s.email = "developers@brightin.nl"
9
+ s.homepage = "http://brightin.nl"
10
+ s.summary = "Brightcontent core"
11
+ s.description = "Brightcontent core"
12
+ s.authors = ["Developers at Brightin"]
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- spec/*`.split("\n")
16
+ s.require_paths = ["lib"]
17
+
18
+ s.add_dependency "rails", "~> 3.2.9"
19
+ s.add_dependency "jquery-rails"
20
+ s.add_dependency "bcrypt-ruby"
21
+ s.add_dependency "inherited_resources"
22
+ s.add_dependency "simple_form"
23
+ s.add_dependency "will_paginate"
24
+ s.add_dependency "bootstrap-wysihtml5-rails"
25
+
26
+ s.add_development_dependency "sqlite3"
27
+ s.add_development_dependency "rspec-rails"
28
+ s.add_development_dependency "capybara"
29
+ s.add_development_dependency "launchy"
30
+ s.add_development_dependency "factory_girl_rails"
31
+ end
@@ -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