brightcontent-pages 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.gitignore +9 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile.lock +173 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +35 -0
  6. data/Rakefile +14 -0
  7. data/app/assets/images/brightcontent/.gitkeep +0 -0
  8. data/app/controllers/brightcontent/pages_controller.rb +16 -0
  9. data/app/helpers/brightcontent/pages_helper.rb +13 -0
  10. data/app/models/brightcontent/page.rb +27 -0
  11. data/app/views/brightcontent/pages/_form_field_parent_id.html.erb +1 -0
  12. data/app/views/brightcontent/pages/_list_field_name.html.erb +1 -0
  13. data/brightcontent-pages.gemspec +26 -0
  14. data/config/routes.rb +3 -0
  15. data/db/migrate/20121207132810_create_brightcontent_pages.rb +16 -0
  16. data/lib/brightcontent/pages/engine.rb +14 -0
  17. data/lib/brightcontent/pages/methods.rb +9 -0
  18. data/lib/brightcontent/pages/version.rb +5 -0
  19. data/lib/brightcontent/pages.rb +10 -0
  20. data/lib/brightcontent-pages.rb +1 -0
  21. data/lib/generators/brightcontent/pages/install_generator.rb +15 -0
  22. data/script/rails +8 -0
  23. data/spec/dummy/README.rdoc +261 -0
  24. data/spec/dummy/Rakefile +7 -0
  25. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  26. data/spec/dummy/app/assets/javascripts/brightcontent/custom.js +1 -0
  27. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  28. data/spec/dummy/app/assets/stylesheets/brightcontent/custom.css +1 -0
  29. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  30. data/spec/dummy/app/controllers/brightcontent/blogs_controller.rb +2 -0
  31. data/spec/dummy/app/controllers/pages_controller.rb +8 -0
  32. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  33. data/spec/dummy/app/mailers/.gitkeep +0 -0
  34. data/spec/dummy/app/models/.gitkeep +0 -0
  35. data/spec/dummy/app/models/blog.rb +3 -0
  36. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  37. data/spec/dummy/app/views/pages/index.html.erb +1 -0
  38. data/spec/dummy/config/application.rb +59 -0
  39. data/spec/dummy/config/boot.rb +10 -0
  40. data/spec/dummy/config/database.yml +25 -0
  41. data/spec/dummy/config/environment.rb +5 -0
  42. data/spec/dummy/config/environments/development.rb +37 -0
  43. data/spec/dummy/config/environments/production.rb +67 -0
  44. data/spec/dummy/config/environments/test.rb +37 -0
  45. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  46. data/spec/dummy/config/initializers/brightcontent.rb +3 -0
  47. data/spec/dummy/config/initializers/inflections.rb +15 -0
  48. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  49. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  50. data/spec/dummy/config/initializers/session_store.rb +8 -0
  51. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  52. data/spec/dummy/config/locales/en.yml +5 -0
  53. data/spec/dummy/config/routes.rb +6 -0
  54. data/spec/dummy/config.ru +4 -0
  55. data/spec/dummy/db/schema.rb +44 -0
  56. data/spec/dummy/lib/assets/.gitkeep +0 -0
  57. data/spec/dummy/public/404.html +26 -0
  58. data/spec/dummy/public/422.html +26 -0
  59. data/spec/dummy/public/500.html +25 -0
  60. data/spec/dummy/public/favicon.ico +0 -0
  61. data/spec/dummy/script/rails +6 -0
  62. data/spec/factories.rb +16 -0
  63. data/spec/features/menu_spec.rb +16 -0
  64. data/spec/features/pages_spec.rb +18 -0
  65. data/spec/models/brightcontent/page_spec.rb +49 -0
  66. data/spec/spec_helper.rb +18 -0
  67. data/spec/support/acceptance_helper.rb +8 -0
  68. metadata +274 -0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/migrate/*.brightcontent.rb
5
+ spec/dummy/db/*.sqlite3
6
+ spec/dummy/log/*.log
7
+ spec/dummy/tmp/
8
+ spec/dummy/.sass-cache
9
+ vendor/bundle
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'brightcontent-core', path: '../core'
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,173 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ brightcontent-pages (0.0.1)
5
+ awesome_nested_set
6
+ brightcontent-core
7
+
8
+ PATH
9
+ remote: ../core
10
+ specs:
11
+ brightcontent-core (2.0.0.alpha2)
12
+ bcrypt-ruby
13
+ bootstrap-wysihtml5-rails
14
+ inherited_resources
15
+ jquery-rails
16
+ rails (~> 3.2.9)
17
+ simple_form
18
+ will_paginate
19
+
20
+ GEM
21
+ remote: http://rubygems.org/
22
+ specs:
23
+ actionmailer (3.2.9)
24
+ actionpack (= 3.2.9)
25
+ mail (~> 2.4.4)
26
+ actionpack (3.2.9)
27
+ activemodel (= 3.2.9)
28
+ activesupport (= 3.2.9)
29
+ builder (~> 3.0.0)
30
+ erubis (~> 2.7.0)
31
+ journey (~> 1.0.4)
32
+ rack (~> 1.4.0)
33
+ rack-cache (~> 1.2)
34
+ rack-test (~> 0.6.1)
35
+ sprockets (~> 2.2.1)
36
+ activemodel (3.2.9)
37
+ activesupport (= 3.2.9)
38
+ builder (~> 3.0.0)
39
+ activerecord (3.2.9)
40
+ activemodel (= 3.2.9)
41
+ activesupport (= 3.2.9)
42
+ arel (~> 3.0.2)
43
+ tzinfo (~> 0.3.29)
44
+ activeresource (3.2.9)
45
+ activemodel (= 3.2.9)
46
+ activesupport (= 3.2.9)
47
+ activesupport (3.2.9)
48
+ i18n (~> 0.6)
49
+ multi_json (~> 1.0)
50
+ addressable (2.3.2)
51
+ arel (3.0.2)
52
+ awesome_nested_set (2.1.5)
53
+ activerecord (>= 3.0.0)
54
+ bcrypt-ruby (3.0.1)
55
+ bootstrap-wysihtml5-rails (0.3.1.13)
56
+ railties (>= 3.0)
57
+ builder (3.0.4)
58
+ capybara (2.0.1)
59
+ mime-types (>= 1.16)
60
+ nokogiri (>= 1.3.3)
61
+ rack (>= 1.0.0)
62
+ rack-test (>= 0.5.4)
63
+ selenium-webdriver (~> 2.0)
64
+ xpath (~> 1.0.0)
65
+ childprocess (0.3.6)
66
+ ffi (~> 1.0, >= 1.0.6)
67
+ diff-lcs (1.1.3)
68
+ erubis (2.7.0)
69
+ factory_girl (4.1.0)
70
+ activesupport (>= 3.0.0)
71
+ factory_girl_rails (4.1.0)
72
+ factory_girl (~> 4.1.0)
73
+ railties (>= 3.0.0)
74
+ ffi (1.2.0)
75
+ has_scope (0.5.1)
76
+ hike (1.2.1)
77
+ i18n (0.6.1)
78
+ inherited_resources (1.3.1)
79
+ has_scope (~> 0.5.0)
80
+ responders (~> 0.6)
81
+ journey (1.0.4)
82
+ jquery-rails (2.1.4)
83
+ railties (>= 3.0, < 5.0)
84
+ thor (>= 0.14, < 2.0)
85
+ json (1.7.5)
86
+ launchy (2.1.2)
87
+ addressable (~> 2.3)
88
+ libwebsocket (0.1.7.1)
89
+ addressable
90
+ websocket
91
+ mail (2.4.4)
92
+ i18n (>= 0.4.0)
93
+ mime-types (~> 1.16)
94
+ treetop (~> 1.4.8)
95
+ mime-types (1.19)
96
+ multi_json (1.5.0)
97
+ nokogiri (1.5.6)
98
+ polyglot (0.3.3)
99
+ rack (1.4.1)
100
+ rack-cache (1.2)
101
+ rack (>= 0.4)
102
+ rack-ssl (1.3.2)
103
+ rack
104
+ rack-test (0.6.2)
105
+ rack (>= 1.0)
106
+ rails (3.2.9)
107
+ actionmailer (= 3.2.9)
108
+ actionpack (= 3.2.9)
109
+ activerecord (= 3.2.9)
110
+ activeresource (= 3.2.9)
111
+ activesupport (= 3.2.9)
112
+ bundler (~> 1.0)
113
+ railties (= 3.2.9)
114
+ railties (3.2.9)
115
+ actionpack (= 3.2.9)
116
+ activesupport (= 3.2.9)
117
+ rack-ssl (~> 1.3.2)
118
+ rake (>= 0.8.7)
119
+ rdoc (~> 3.4)
120
+ thor (>= 0.14.6, < 2.0)
121
+ rake (10.0.3)
122
+ rdoc (3.12)
123
+ json (~> 1.4)
124
+ responders (0.9.3)
125
+ railties (~> 3.1)
126
+ rspec-core (2.12.2)
127
+ rspec-expectations (2.12.1)
128
+ diff-lcs (~> 1.1.3)
129
+ rspec-mocks (2.12.1)
130
+ rspec-rails (2.12.0)
131
+ actionpack (>= 3.0)
132
+ activesupport (>= 3.0)
133
+ railties (>= 3.0)
134
+ rspec-core (~> 2.12.0)
135
+ rspec-expectations (~> 2.12.0)
136
+ rspec-mocks (~> 2.12.0)
137
+ rubyzip (0.9.9)
138
+ selenium-webdriver (2.27.2)
139
+ childprocess (>= 0.2.5)
140
+ libwebsocket (~> 0.1.3)
141
+ multi_json (~> 1.0)
142
+ rubyzip
143
+ simple_form (2.0.4)
144
+ actionpack (~> 3.0)
145
+ activemodel (~> 3.0)
146
+ sprockets (2.2.2)
147
+ hike (~> 1.2)
148
+ multi_json (~> 1.0)
149
+ rack (~> 1.0)
150
+ tilt (~> 1.1, != 1.3.0)
151
+ sqlite3 (1.3.6)
152
+ thor (0.16.0)
153
+ tilt (1.3.3)
154
+ treetop (1.4.12)
155
+ polyglot
156
+ polyglot (>= 0.3.1)
157
+ tzinfo (0.3.35)
158
+ websocket (1.0.6)
159
+ will_paginate (3.0.3)
160
+ xpath (1.0.0)
161
+ nokogiri (~> 1.3)
162
+
163
+ PLATFORMS
164
+ ruby
165
+
166
+ DEPENDENCIES
167
+ brightcontent-core!
168
+ brightcontent-pages!
169
+ capybara
170
+ factory_girl_rails
171
+ launchy
172
+ rspec-rails
173
+ sqlite3
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ Requirements
2
+ ------------
3
+
4
+ Brightcontent
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Include the gem in your Gemfile:
10
+
11
+ ```ruby
12
+ gem "brightcontent", :git => "git://github.com/stexy/brightcontent.git"
13
+ gem "brightcontent-pages", :git => "git://github.com/stexy/brightcontent-pages.git"
14
+ bundle install
15
+ ```
16
+
17
+ Generate the initializer, copy migrations and edit routes file. This can be done via a generator. Migrate the database afterwards:
18
+
19
+ $ rails generate brightcontent:install
20
+ $ rails generate brightcontent:pages:install
21
+ $ rake db:migrate
22
+
23
+ Go to `/admin` and login with default user (email: `admin@example.com` / password: `password`).
24
+
25
+
26
+ Usage
27
+ -----
28
+
29
+ Pages gives you a Page model with tree structure and pretty urls. Every page relates to a specific path. For example, you could create a page with the path `/about/team`. The page is available on the url via `current_page`.
30
+
31
+ This adds an extra layer on top of your existing routes. However when there aren't any routes available for the specific url, Rails cannot render the page. Therefore it is best to add a catch-all route (at the very bottom of the file) for all general pages:
32
+
33
+ ```ruby
34
+ get "*path" => "pages#show"
35
+ ```
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
8
+ load 'rails/tasks/engine.rake'
9
+
10
+ require 'rspec/core/rake_task'
11
+ RSpec::Core::RakeTask.new(:spec)
12
+ task :default => :spec
13
+
14
+ Bundler::GemHelper.install_tasks
File without changes
@@ -0,0 +1,16 @@
1
+ require_dependency "brightcontent/application_controller"
2
+
3
+ module Brightcontent
4
+ class PagesController < BaseController
5
+ private
6
+
7
+ def list_fields
8
+ default_fields - %w{body depth lft rgt parent_id slug}
9
+ end
10
+
11
+ def form_fields
12
+ default_fields - %w{slug depth lft rgt}
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Brightcontent
2
+ module PagesHelper
3
+ def page_selector(current_page)
4
+ Page.all.map do |page|
5
+ ["#{page_prefix(page.depth)} #{page.name}", page.id] if page != current_page
6
+ end.compact
7
+ end
8
+
9
+ def page_prefix(depth)
10
+ "-" * depth
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ module Brightcontent
2
+ class Page < ActiveRecord::Base
3
+ acts_as_nested_set
4
+ attr_accessible :body, :name, :parent_id
5
+
6
+ validates_presence_of :name
7
+
8
+ after_save :update_slug
9
+
10
+ default_scope order('lft')
11
+
12
+ def homepage?
13
+ lft == 1
14
+ end
15
+
16
+ private
17
+
18
+ def update_slug
19
+ self.update_column(:slug, slug_name)
20
+ end
21
+
22
+ def slug_name
23
+ homepage? ? "" : self_and_ancestors.map { |p| p.name.parameterize }.join("/")
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1 @@
1
+ <%= form.input :parent_id, collection: page_selector(form.object) %>
@@ -0,0 +1 @@
1
+ <%= "—" * item.depth %> <%= item.name %>
@@ -0,0 +1,26 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require "brightcontent/pages/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "brightcontent-pages"
7
+ s.version = Brightcontent::Pages::VERSION
8
+ s.email = "developers@brightin.nl"
9
+ s.homepage = "http://brightin.nl"
10
+ s.summary = "Pages resource for brightcontent"
11
+ s.description = "Separate pages resource for brightcontent"
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 "brightcontent-core"
19
+ s.add_dependency "awesome_nested_set"
20
+
21
+ s.add_development_dependency "sqlite3"
22
+ s.add_development_dependency "rspec-rails"
23
+ s.add_development_dependency "capybara"
24
+ s.add_development_dependency "launchy"
25
+ s.add_development_dependency "factory_girl_rails"
26
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Brightcontent::Engine.routes.draw do
2
+ resources :pages
3
+ end
@@ -0,0 +1,16 @@
1
+ class CreateBrightcontentPages < ActiveRecord::Migration
2
+ def change
3
+ create_table :brightcontent_pages do |t|
4
+ t.string :name
5
+ t.text :body
6
+ t.string :slug
7
+ t.integer :depth
8
+ t.integer :lft
9
+ t.integer :rgt
10
+ t.integer :parent_id
11
+
12
+ t.timestamps
13
+ end
14
+ add_index :brightcontent_pages, :slug
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module Brightcontent
2
+ module Pages
3
+ class Engine < ::Rails::Engine
4
+ initializer "Include Page methods" do
5
+ ActiveSupport.on_load(:action_controller) do
6
+ include Methods
7
+ end
8
+ ActiveSupport.on_load(:action_view) do
9
+ include Methods
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module Brightcontent
2
+ module Pages
3
+ module Methods
4
+ def current_page
5
+ @current_page ||= Page.find_by_slug(request.fullpath[1..-1])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Brightcontent
2
+ module Pages
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require "brightcontent-core"
2
+ require "awesome_nested_set"
3
+
4
+ require "brightcontent/pages/engine"
5
+
6
+ module Brightcontent
7
+ module Pages
8
+ autoload :Methods, 'brightcontent/pages/methods'
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ require "brightcontent/pages"
@@ -0,0 +1,15 @@
1
+ module Brightcontent
2
+ module Pages
3
+ module Generators
4
+ class InstallGenerator < Rails::Generators::Base
5
+
6
+ desc "Install migrations for Brightcontent Pages"
7
+
8
+ def copy_migrations
9
+ rake "brightcontent_pages_engine:install:migrations"
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
data/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'