refinerycms-pages 0.9.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/app/controllers/admin/page_parts_controller.rb +24 -0
  2. data/app/controllers/admin/pages_controller.rb +37 -0
  3. data/app/controllers/admin/pages_dialogs_controller.rb +87 -0
  4. data/app/controllers/pages_controller.rb +31 -0
  5. data/app/helpers/pages_helper.rb +2 -0
  6. data/app/models/page.rb +274 -0
  7. data/app/models/page_part.rb +23 -0
  8. data/app/presenters/page_presenter.rb +7 -0
  9. data/app/views/admin/pages/_form.html.erb +61 -0
  10. data/app/views/admin/pages/_form_advanced_options.html.erb +79 -0
  11. data/app/views/admin/pages/_form_advanced_options_seo.html.erb +24 -0
  12. data/app/views/admin/pages/_form_fields_after_title.html.erb +1 -0
  13. data/app/views/admin/pages/_form_new_page_parts.html.erb +14 -0
  14. data/app/views/admin/pages/_form_page_parts.html.erb +47 -0
  15. data/app/views/admin/pages/_locale_picker.html.erb +11 -0
  16. data/app/views/admin/pages/_page.html.erb +35 -0
  17. data/app/views/admin/pages/_page_part_field.html.erb +5 -0
  18. data/app/views/admin/pages/_sortable_list.html.erb +5 -0
  19. data/app/views/admin/pages/edit.html.erb +1 -0
  20. data/app/views/admin/pages/index.html.erb +40 -0
  21. data/app/views/admin/pages/new.html.erb +1 -0
  22. data/app/views/admin/pages_dialogs/_page_link.html.erb +13 -0
  23. data/app/views/admin/pages_dialogs/link_to.html.erb +141 -0
  24. data/app/views/pages/home.html.erb +1 -0
  25. data/app/views/pages/show.html.erb +1 -0
  26. data/config/locales/cs.yml +84 -0
  27. data/config/locales/da.yml +84 -0
  28. data/config/locales/de.yml +84 -0
  29. data/config/locales/el.yml +84 -0
  30. data/config/locales/en.yml +84 -0
  31. data/config/locales/es.yml +83 -0
  32. data/config/locales/fr.yml +84 -0
  33. data/config/locales/it.yml +98 -0
  34. data/config/locales/lolcat.yml +83 -0
  35. data/config/locales/lt.yml +85 -0
  36. data/config/locales/lv.yml +86 -0
  37. data/config/locales/nb.yml +85 -0
  38. data/config/locales/nl.yml +81 -0
  39. data/config/locales/pl.yml +85 -0
  40. data/config/locales/pt-BR.yml +85 -0
  41. data/config/locales/rs.yml +84 -0
  42. data/config/locales/ru.yml +108 -0
  43. data/config/locales/sl.yml +83 -0
  44. data/config/locales/sv.yml +84 -0
  45. data/config/locales/vi.yml +84 -0
  46. data/config/locales/zh-CN.yml +84 -0
  47. data/config/locales/zh-TW.yml +84 -0
  48. data/config/routes.rb +21 -0
  49. data/db/migrate/20100913234708_create_refinerycms_pages_schema.rb +53 -0
  50. data/db/migrate/20101214040815_translate_page_plugin.rb +29 -0
  51. data/db/migrate/20101216194133_remove_cached_slug_from_pages.rb +9 -0
  52. data/db/seeds/pages.rb +43 -0
  53. data/features/manage_pages.feature +47 -0
  54. data/features/step_definitions/page_steps.rb +53 -0
  55. data/features/support/paths.rb +26 -0
  56. data/features/visit_pages.feature +47 -0
  57. data/lib/gemspec.rb +33 -0
  58. data/lib/generators/refinerycms_pages_generator.rb +8 -0
  59. data/lib/pages/marketable_routes.rb +10 -0
  60. data/lib/pages/tabs.rb +30 -0
  61. data/lib/refinerycms-pages.rb +45 -0
  62. data/license.md +21 -0
  63. data/readme.md +156 -0
  64. data/refinerycms-pages.gemspec +110 -0
  65. data/spec/models/page_spec.rb +144 -0
  66. metadata +133 -0
@@ -0,0 +1,53 @@
1
+ class CreateRefinerycmsPagesSchema < ActiveRecord::Migration
2
+ def self.up
3
+ create_table ::PagePart.table_name, :force => true do |t|
4
+ t.integer "page_id"
5
+ t.string "title"
6
+ t.text "body"
7
+ t.integer "position"
8
+ t.datetime "created_at"
9
+ t.datetime "updated_at"
10
+ end
11
+
12
+ add_index ::PagePart.table_name, ["id"], :name => "index_#{::PagePart.table_name}_on_id"
13
+ add_index ::PagePart.table_name, ["page_id"], :name => "index_#{::PagePart.table_name}_on_page_id"
14
+
15
+ create_table ::Page.table_name, :force => true do |t|
16
+ t.string "title"
17
+ t.integer "parent_id"
18
+ t.integer "position"
19
+ t.string "path"
20
+ t.datetime "created_at"
21
+ t.datetime "updated_at"
22
+ t.string "meta_keywords"
23
+ t.text "meta_description"
24
+ t.boolean "show_in_menu", :default => true
25
+ t.string "link_url"
26
+ t.string "menu_match"
27
+ t.boolean "deletable", :default => true
28
+ t.string "custom_title"
29
+ t.string "custom_title_type", :default => "none"
30
+ t.boolean "draft", :default => false
31
+ t.string "browser_title"
32
+ t.boolean "skip_to_first_child", :default => false
33
+ t.integer "lft"
34
+ t.integer "rgt"
35
+ t.integer "depth"
36
+ t.string "cached_slug"
37
+ end
38
+
39
+ add_index ::Page.table_name, ["depth"], :name => "index_#{::Page.table_name}_on_depth"
40
+ add_index ::Page.table_name, ["id"], :name => "index_#{::Page.table_name}_on_id"
41
+ add_index ::Page.table_name, ["lft"], :name => "index_#{::Page.table_name}_on_lft"
42
+ add_index ::Page.table_name, ["parent_id"], :name => "index_#{::Page.table_name}_on_parent_id"
43
+ add_index ::Page.table_name, ["rgt"], :name => "index_#{::Page.table_name}_on_rgt"
44
+ end
45
+
46
+ def self.down
47
+ [::Page, ::PagePart].reject{|m|
48
+ !(defined?(m) and m.respond_to?(:table_name))
49
+ }.each do |model|
50
+ drop_table model.table_name
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,29 @@
1
+ class TranslatePagePlugin < ActiveRecord::Migration
2
+ def self.up
3
+ PagePart.create_translation_table!({
4
+ :body => :text
5
+ }, {
6
+ :migrate_data => true
7
+ })
8
+
9
+ Page.create_translation_table!({
10
+ :title => :string,
11
+ :meta_keywords => :string,
12
+ :meta_description => :text,
13
+ :browser_title => :string
14
+ }, {
15
+ :migrate_data => true
16
+ })
17
+
18
+ if (seed_file = Rails.root.join('db', 'seeds', 'pages.rb')).file?
19
+ load seed_file.to_s unless Page.where(:link_url => '/').any?
20
+ end
21
+
22
+ Slug.update_all(:locale => ::I18n.locale)
23
+ end
24
+
25
+ def self.down
26
+ Page.drop_translation_table! :migrate_data => true
27
+ PagePart.drop_translation_table! :migrate_data => true
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ class RemoveCachedSlugFromPages < ActiveRecord::Migration
2
+ def self.up
3
+ remove_column :pages, :cached_slug
4
+ end
5
+
6
+ def self.down
7
+ add_column :pages, :cached_slug, :string
8
+ end
9
+ end
data/db/seeds/pages.rb ADDED
@@ -0,0 +1,43 @@
1
+ page_position = -1
2
+
3
+ home_page = Page.create(:title => "Home",
4
+ :deletable => false,
5
+ :link_url => "/",
6
+ :menu_match => "^/$",
7
+ :position => (page_position += 1))
8
+ home_page.parts.create({
9
+ :title => "Body",
10
+ :body => "<p>Welcome to our site. This is just a place holder page while we gather our content.</p>",
11
+ :position => 0
12
+ })
13
+ home_page.parts.create({
14
+ :title => "Side Body",
15
+ :body => "<p>This is another block of content over here.</p>",
16
+ :position => 1
17
+ })
18
+
19
+ home_page_position = -1
20
+ page_not_found_page = home_page.children.create(:title => "Page not found",
21
+ :menu_match => "^/404$",
22
+ :show_in_menu => false,
23
+ :deletable => false,
24
+ :position => (home_page_position += 1))
25
+ page_not_found_page.parts.create({
26
+ :title => "Body",
27
+ :body => "<h2>Sorry, there was a problem...</h2><p>The page you requested was not found.</p><p><a href='/'>Return to the home page</a></p>",
28
+ :position => 0
29
+ })
30
+
31
+ about_us_page = Page.create(:title => "About",
32
+ :deletable => true,
33
+ :position => (page_position += 1))
34
+ about_us_page.parts.create({
35
+ :title => "Body",
36
+ :body => "<p>This is just a standard text page example. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin metus dolor, hendrerit sit amet, aliquet nec, posuere sed, purus. Nullam et velit iaculis odio sagittis placerat. Duis metus tellus, pellentesque ut, luctus id, egestas a, lorem. Praesent vitae mauris. Aliquam sed nulla. Sed id nunc vitae leo suscipit viverra. Proin at leo ut lacus consequat rhoncus. In hac habitasse platea dictumst. Nunc quis tortor sed libero hendrerit dapibus.\n\nInteger interdum purus id erat. Duis nec velit vitae dolor mattis euismod. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse pellentesque dignissim lacus. Nulla semper euismod arcu. Suspendisse egestas, erat a consectetur dapibus, felis orci cursus eros, et sollicitudin purus urna et metus. Integer eget est sed nunc euismod vestibulum. Integer nulla dui, tristique in, euismod et, interdum imperdiet, enim. Mauris at lectus. Sed egestas tortor nec mi.</p>",
37
+ :position => 0
38
+ })
39
+ about_us_page.parts.create({
40
+ :title => "Side Body",
41
+ :body => "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus fringilla nisi a elit. Duis ultricies orci ut arcu. Ut ac nibh. Duis blandit rhoncus magna. Pellentesque semper risus ut magna. Etiam pulvinar tellus eget diam. Morbi blandit. Donec pulvinar mauris at ligula. Sed pellentesque, ipsum id congue molestie, lectus risus egestas pede, ac viverra diam lacus ac urna. Aenean elit.</p>",
42
+ :position => 1
43
+ })
@@ -0,0 +1,47 @@
1
+ @refinerycms @pages @pages-manage
2
+ Feature: Manage Pages
3
+ In order to control the content on my website
4
+ As an administrator
5
+ I want to create and manage pages
6
+
7
+ Background:
8
+ Given I am a logged in refinery user
9
+ And I have no pages
10
+
11
+ Scenario: Pages List
12
+ Given I have pages titled Home, About
13
+ When I go to the list of pages
14
+ Then I should see "Home"
15
+ And I should see "About"
16
+
17
+ Scenario: Create Valid Page
18
+ When I go to the list of pages
19
+ And I follow "Add new page"
20
+ And I fill in "Title" with "Pickles are Cucumbers Soaked in Evil"
21
+ And I press "Save"
22
+ Then I should see "'Pickles are Cucumbers Soaked in Evil' was successfully added."
23
+ And I should have 1 page
24
+
25
+ Scenario: Create Invalid Page (without title)
26
+ When I go to the list of pages
27
+ And I follow "Add new page"
28
+ And I press "Save"
29
+ Then I should see "Title can't be blank"
30
+ And I should have 0 pages
31
+
32
+ Scenario: Create Duplicate Page
33
+ Given I only have pages titled Home, About
34
+ When I go to the list of pages
35
+ And I follow "Add new page"
36
+ And I fill in "Title" with "About"
37
+ And I press "Save"
38
+ Then I should have 3 pages
39
+ And I should have a page at /about--2
40
+
41
+ Scenario: Delete Page
42
+ Given I only have a page titled "test"
43
+ When I go to the list of pages
44
+ And I follow "Remove this page forever"
45
+ Then I should see "'test' was successfully removed."
46
+ And I should have 0 pages
47
+ And I should have 0 page_parts
@@ -0,0 +1,53 @@
1
+ Given /^I (only )?have a page titled "?([^\"]*)"? with a custom url "?([^\"]*)"?$/ do |only, title, link_url|
2
+ Page.delete_all if only
3
+
4
+ Page.create(:title => title,
5
+ :link_url => link_url)
6
+ end
7
+
8
+ Given /^the page titled "?([^\"]*)"? has a menu match "?([^\"]*)"?$/ do |title, menu_match|
9
+ Page.where(:title => title).first.update_attribute(:menu_match, menu_match)
10
+ end
11
+
12
+ Given /^I (only )?have pages titled "?([^\"]*)"?$/ do |only, titles|
13
+ Page.delete_all if only
14
+ titles.split(', ').each do |title|
15
+ Page.create(:title => title)
16
+ end
17
+ end
18
+
19
+ Given /^I have no pages$/ do
20
+ Page.delete_all
21
+ end
22
+
23
+ Given /^I (only )?have a page titled "?([^\"]*)"?$/ do |only, title|
24
+ Page.delete_all if only
25
+ PagePart.delete_all if only
26
+ page = Page.create(:title => title)
27
+ page.parts << PagePart.new(:title => 'testing', :position => 0)
28
+ page
29
+ end
30
+
31
+ Given /^the page titled "?([^\"]*)"? is a child of "?([^\"]*)"?$/ do |title, parent_title|
32
+ Page.where(:title => title).first.update_attribute(:parent, Page.where(:title => parent_title).first)
33
+ end
34
+
35
+ Given /^the page titled "?([^\"]*)"? is not shown in the menu$/ do |title|
36
+ Page.where(:title => title).first.update_attribute(:show_in_menu, false)
37
+ end
38
+
39
+ Given /^the page titled "?([^\"]*)"? is draft$/ do |title|
40
+ Page.where(:title => title).first.update_attribute(:draft, true)
41
+ end
42
+
43
+ Then /^I should have ([0-9]+) pages?$/ do |count|
44
+ Page.count.should == count.to_i
45
+ end
46
+
47
+ Then /^I should have a page at \/(.+)$/ do |url|
48
+ Page.all.count{|page| page.url[:path].to_s.include?(url)}.should == 1
49
+ end
50
+
51
+ Then /^I should have (\d+) page_parts$/ do |count|
52
+ PagePart.count.should == count.to_i
53
+ end
@@ -0,0 +1,26 @@
1
+ module NavigationHelpers
2
+ module Refinery
3
+ module Pages
4
+ def path_to(page_name)
5
+ case page_name
6
+ when /the home\s?page/
7
+ root_path
8
+ when /the list of pages/
9
+ admin_pages_path
10
+ when /the new page form/
11
+ new_admin_page_path
12
+ else
13
+ begin
14
+ if page_name =~ /the page titled "?([^\"]*)"?/ and (page = Page.where(:title => $1).first).present?
15
+ self.url_for(page.url)
16
+ else
17
+ nil
18
+ end
19
+ rescue
20
+ nil
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,47 @@
1
+ @refinerycms @pages @pages-visit @visit-pages
2
+ Feature: Visit Pages
3
+ In order to view the content on this website
4
+ As a visitor
5
+ I want to view pages
6
+
7
+ Background:
8
+ Given A Refinery user exists
9
+ And I have a page titled "Home" with a custom url "/"
10
+ And I have a page titled "About"
11
+ And I have a page titled "ä ö ü spéciål chåråctÉrs"
12
+ And I have a page titled "Hidden"
13
+ And the page titled "Hidden" is a child of Home
14
+ And the page titled "Hidden" is not shown in the menu
15
+
16
+ Scenario: Home Page
17
+ When I go to the home page
18
+ Then I should see "Home"
19
+ And I should see "About"
20
+ And I should see "Home" within ".selected"
21
+
22
+ Scenario: Content Page
23
+ When I go to the page titled "About"
24
+ Then I should see "Home"
25
+ And I should see "About"
26
+ And I should see "About" within ".selected > a"
27
+
28
+ Scenario: Special Characters Title
29
+ When I go to the page titled "ä ö ü spéciål chåråctÉrs"
30
+ Then I should see "Home"
31
+ And I should see "About"
32
+ And I should see "ä ö ü spéciål chåråctÉrs"
33
+ And I should see "ä ö ü spéciål chåråctÉrs" within ".selected > a"
34
+
35
+ Scenario: Special Characters Title as submenu page
36
+ Given the page titled "ä ö ü spéciål chåråctÉrs" is a child of About
37
+ When I go to the page titled "ä ö ü spéciål chåråctÉrs"
38
+ Then I should see "Home"
39
+ And I should see "About"
40
+ And I should see "ä ö ü spéciål chåråctÉrs"
41
+ And I should see "ä ö ü spéciål chåråctÉrs" within ".selected * > .selected a"
42
+
43
+ Scenario: Hidden Page
44
+ When I go to the page titled "Hidden"
45
+ Then I should see "Home"
46
+ And I should see "About"
47
+ And I should see "Home" within ".selected > a"
data/lib/gemspec.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'pathname'
2
+ gempath = Pathname.new(File.expand_path('../../', __FILE__))
3
+ require gempath.join('..', 'base', 'lib', 'base', 'refinery')
4
+
5
+ gemspec = <<EOF
6
+ # DO NOT EDIT THIS FILE DIRECTLY! Instead, use lib/gemspec.rb to generate it.
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = %q{#{gemname = 'refinerycms-pages'}}
10
+ s.version = %q{#{::Refinery.version}}
11
+ s.summary = %q{Pages engine for Refinery CMS}
12
+ s.description = %q{The default content engine of Refinery CMS. This engine handles the administration and display of user-editable pages.}
13
+ s.date = %q{#{Time.now.strftime('%Y-%m-%d')}}
14
+ s.email = %q{info@refinerycms.com}
15
+ s.homepage = %q{http://refinerycms.com}
16
+ s.rubyforge_project = %q{refinerycms}
17
+ s.authors = ['Resolve Digital', 'Philip Arndt', 'David Jones', 'Steven Heidel']
18
+ s.license = %q{MIT}
19
+ s.require_paths = %w(lib)
20
+ s.executables = %w(#{Pathname.glob(gempath.join('bin/*')).map{|d| d.relative_path_from(gempath)}.sort.join(" ")})
21
+
22
+ s.files = [
23
+ '#{%w( **/{*,.rspec,.gitignore,.yardopts} ).map { |file| Pathname.glob(gempath.join(file)) }.flatten.reject{|f|
24
+ !f.exist? or f.to_s =~ /\.gem$/ or (f.directory? and f.children.empty?)
25
+ }.map{|d| d.relative_path_from(gempath)}.uniq.sort.join("',\n '")}'
26
+ ]
27
+
28
+ s.add_dependency 'refinerycms-core', '~> #{::Refinery::Version}'
29
+ end
30
+ EOF
31
+
32
+ (gemfile = gempath.join("#{gemname}.gemspec")).open('w') {|f| f.puts(gemspec)}
33
+ puts `cd #{gempath} && gem build #{gemfile}` if ARGV.any?{|a| a == "BUILD=true"}
@@ -0,0 +1,8 @@
1
+ require 'refinery/generators'
2
+
3
+ class RefinerycmsPages < ::Refinery::Generators::EngineInstaller
4
+
5
+ source_root File.expand_path('../../../', __FILE__)
6
+ engine_name "pages"
7
+
8
+ end
@@ -0,0 +1,10 @@
1
+ ::Refinery::Application.routes.draw do
2
+ match '*path' => 'pages#show'
3
+ end
4
+
5
+ # Add any parts of routes as reserved words.
6
+ if Page.use_marketable_urls?
7
+ Page.friendly_id_config.reserved_words |= ::Refinery::Application.routes.named_routes.map { |name, route|
8
+ route.path.gsub(/^\//, '').to_s.split('(').first.split(':').first.to_s.split('/')
9
+ }.flatten.uniq
10
+ end
data/lib/pages/tabs.rb ADDED
@@ -0,0 +1,30 @@
1
+ module Refinery
2
+ module Pages
3
+
4
+ attr_accessor :tabs
5
+
6
+ def self.tabs
7
+ @tabs ||= []
8
+ end
9
+
10
+ class Tab
11
+ attr_accessor :name, :partial
12
+
13
+ def self.register(&block)
14
+ tab = self.new
15
+
16
+ yield tab
17
+
18
+ raise "A tab MUST have a name!: #{tab.inspect}" if tab.name.blank?
19
+ raise "A tab MUST have a partial!: #{tab.inspect}" if tab.partial.blank?
20
+ end
21
+
22
+ protected
23
+
24
+ def initialize
25
+ ::Refinery::Pages.tabs << self # add me to the collection of registered page tabs
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,45 @@
1
+ require 'refinerycms-core'
2
+ require 'awesome_nested_set'
3
+ require 'globalize3'
4
+
5
+ module Refinery
6
+ module Pages
7
+
8
+ class << self
9
+ attr_accessor :root
10
+ def root
11
+ @root ||= Pathname.new(File.expand_path('../../', __FILE__))
12
+ end
13
+ end
14
+
15
+ class Engine < ::Rails::Engine
16
+
17
+ config.to_prepare do
18
+ require File.expand_path('../pages/tabs', __FILE__)
19
+ end
20
+
21
+ config.after_initialize do
22
+ ::Refinery::Plugin.register do |plugin|
23
+ plugin.name = "refinery_pages"
24
+ plugin.directory = "pages"
25
+ plugin.version = %q{0.9.9}
26
+ plugin.menu_match = /(refinery|admin)\/page(_part)?s(_dialogs)?$/
27
+ plugin.activity = {
28
+ :class => Page,
29
+ :url_prefix => "edit",
30
+ :title => "title",
31
+ :created_image => "page_add.png",
32
+ :updated_image => "page_edit.png"
33
+ }
34
+ end
35
+ end
36
+
37
+ initializer 'add marketable routes' do |app|
38
+ app.routes_reloader.paths << File.expand_path('../pages/marketable_routes.rb', __FILE__)
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+
45
+ ::Refinery.engines << 'pages'