cmor_cms 0.0.1.pre

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 (74) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +88 -0
  4. data/Rakefile +19 -0
  5. data/app/assets/javascripts/cmor/cms/application.js +1 -0
  6. data/app/assets/javascripts/cmor/cms/application/navigations.js.coffee +4 -0
  7. data/app/assets/javascripts/cmor_cms.js +1 -0
  8. data/app/assets/stylesheets/cmor/cms/application.css +3 -0
  9. data/app/assets/stylesheets/cmor/cms/application/keep.css +0 -0
  10. data/app/assets/stylesheets/cmor_cms.css +3 -0
  11. data/app/controllers/cmor/cms/page_controller.rb +54 -0
  12. data/app/importers/navigation.rb +27 -0
  13. data/app/importers/navigation_item.rb +61 -0
  14. data/app/importers/page.rb +38 -0
  15. data/app/models/cmor/cms/content_block.rb +14 -0
  16. data/app/models/cmor/cms/content_box.rb +12 -0
  17. data/app/models/cmor/cms/navigation.rb +18 -0
  18. data/app/models/cmor/cms/navigation_item.rb +86 -0
  19. data/app/models/cmor/cms/page.rb +29 -0
  20. data/app/models/cmor/cms/partial.rb +15 -0
  21. data/app/models/cmor/cms/template.rb +13 -0
  22. data/app/models/concerns/model/cmor/cms/navigation_item/properties_concern.rb +25 -0
  23. data/app/resolvers/cmor/cms/page_resolver.rb +61 -0
  24. data/app/resolvers/cmor/cms/partial_resolver.rb +29 -0
  25. data/app/resolvers/cmor/cms/template_resolver.rb +29 -0
  26. data/app/services/cmor/cms/add_homepages_service.rb +79 -0
  27. data/app/services/cmor/cms/create_navigation_service.rb +49 -0
  28. data/app/services/cmor/cms/import_partials_service.rb +126 -0
  29. data/app/template_handlers/action_view/template/handlers/textile.rb +26 -0
  30. data/app/view_helpers/cmor/cms/application_view_helper.rb +36 -0
  31. data/app/view_helpers/cmor/cms/navigation_view_helper.rb +87 -0
  32. data/app/view_helpers/cmor/cms/page_view_helper.rb +34 -0
  33. data/app/views/cmor/cms/_link_to_top.html.erb +5 -0
  34. data/app/views/cmor/cms/page/fallback.html.erb +2 -0
  35. data/app/views/cmor/cms/page/fallback.txt +1 -0
  36. data/config/initializers/assets.rb +1 -0
  37. data/config/initializers/mime_types.rb +1 -0
  38. data/config/initializers/simple_navigation.rb +1 -0
  39. data/config/initializers/textile_support.rb +3 -0
  40. data/config/locales/de.yml +140 -0
  41. data/config/locales/en.yml +140 -0
  42. data/config/navigation.rb +0 -0
  43. data/config/routes.rb +6 -0
  44. data/db/migrate/002_create_cmor_cms_pages.rb +17 -0
  45. data/db/migrate/003_create_cmor_cms_templates.rb +14 -0
  46. data/db/migrate/004_create_cmor_cms_partials.rb +15 -0
  47. data/db/migrate/005_create_cmor_cms_navigations.rb +13 -0
  48. data/db/migrate/006_create_cmor_cms_navigation_items.rb +29 -0
  49. data/db/migrate/007_create_cmor_cms_content_boxes.rb +9 -0
  50. data/db/migrate/008_create_cmor_cms_content_blocks.rb +15 -0
  51. data/lib/cmor/cms.rb +23 -0
  52. data/lib/cmor/cms/action_view/template_patch.rb +18 -0
  53. data/lib/cmor/cms/action_view/template_renderer_patch.rb +45 -0
  54. data/lib/cmor/cms/configuration.rb +35 -0
  55. data/lib/cmor/cms/controller_extensions/page_resolver.rb +12 -0
  56. data/lib/cmor/cms/controller_extensions/partial_resolver.rb +12 -0
  57. data/lib/cmor/cms/controller_extensions/template_resolver.rb +12 -0
  58. data/lib/cmor/cms/database_resolver.rb +99 -0
  59. data/lib/cmor/cms/database_template.rb +70 -0
  60. data/lib/cmor/cms/engine.rb +16 -0
  61. data/lib/cmor/cms/version.rb +7 -0
  62. data/lib/cmor_cms.rb +8 -0
  63. data/lib/generators/cmor/cms/install/install_generator.rb +34 -0
  64. data/lib/generators/cmor/cms/install/templates/initializer.rb +53 -0
  65. data/lib/generators/cmor/cms/install/templates/routes.source +4 -0
  66. data/lib/tasks/cmor_cms_tasks.rake +15 -0
  67. data/spec/factories/cmor/cms/content_block.rb +7 -0
  68. data/spec/factories/cmor/cms/content_box.rb +5 -0
  69. data/spec/factories/cmor/cms/navigation_items.rb +16 -0
  70. data/spec/factories/cmor/cms/navigations.rb +6 -0
  71. data/spec/factories/cmor/cms/pages.rb +8 -0
  72. data/spec/factories/cmor/cms/partials.rb +7 -0
  73. data/spec/factories/cmor/cms/templates.rb +7 -0
  74. metadata +465 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 01cc330d49bf5d688a4c0908dd6cec7db9716ea3c387570db5bb7f369f7bf192
4
+ data.tar.gz: 9718f8bce27566882856d1ad43908b38df70dc51d666c862ed1ff57a2e8143b7
5
+ SHA512:
6
+ metadata.gz: 485b308aac5aba127fd5f41017520fd7200fcf9ef75e00c46bd6b8f9c2f5c6edd3fa3a0805a7bd78ade36642d5d142faa19ac8f1eee5f71a77069eb19dbd46eb
7
+ data.tar.gz: 7fe9845fa82f0c67b30403f66c117d78b40cd9b4764e5b0b5abfb836934889c642cea2c3d5e0a05ee8e16de68c5b0d1b32b9a249d4ccdb38dad2e6ac21954028
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Roberto Vasquez Angel
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.
@@ -0,0 +1,88 @@
1
+ = CMOR CMS
2
+
3
+ = End-User documentation
4
+
5
+ Please look at the[link:doc] Folder.
6
+
7
+ = Migrating from 1.x.x to 2.0.0
8
+
9
+ Add active_admin-awesome_nested_set to your gemfile, if you are using activeadmin:
10
+
11
+ # Gemfile
12
+ gem 'active_admin-awesome_nested_set'
13
+
14
+ = Prerequisites
15
+
16
+ if you are using activeadmin as backend, cmor_cmss comes with admin files to provide a backend. In that case, you'll need active_admin-awesome_nested_set. Add it to your gemfile:
17
+
18
+ # Gemfile
19
+ gem 'active_admin-awesome_nested_set'
20
+
21
+ You may need to add therubyracer to your Gemfile:
22
+
23
+ # Gemfile
24
+ gem 'therubyracer'
25
+
26
+ = Installation
27
+
28
+ Add it to your bundle:
29
+
30
+ # Gemfile:
31
+ gem 'cmor_cms'
32
+
33
+ Install your bundle:
34
+
35
+ > bundle install
36
+
37
+ Install the intializer:
38
+
39
+ > rails g cmor:cms:install
40
+
41
+ Generate migrations and migrate:
42
+
43
+ > rake cmor_cms:install:migrations
44
+ > rake db:migrate
45
+
46
+ = Optional: Generating example/default data
47
+
48
+ There is a task to prepopulate your database tables with example data.
49
+
50
+ Warning: *RUNNING THIS WILL DELETE ALL OF YOUR CMS DATA AND REPLACE IT WITH EXAMPLE DATA!*
51
+
52
+ > rake cmor:cms:db:populate!
53
+
54
+ = Linking to pages
55
+
56
+ <%= link_to 'My Page', page_path(i18n_locale: I18n.locale, page: 'my-page') %>
57
+
58
+ = Using partials form the database in other controllers
59
+
60
+ # app/controllers/application_controller.rb
61
+ class ApplicationController < ActionController::Base
62
+ prepend_view_path ::Cmor::Cms::PartialResolver.instance
63
+ ...
64
+ end
65
+
66
+ = Using the navigation helper
67
+
68
+ # app/controllers/application_controller.rb
69
+ class ApplicationController < ActionController::Base
70
+ helper Cmor::CmsHelper
71
+ ...
72
+ end
73
+
74
+ Then you can render navigation in your views:
75
+
76
+ # app/views/_navigation.rb
77
+ = cms_render_navigation(:main)
78
+
79
+ = Running specs
80
+
81
+ gem install bundler
82
+ bundle
83
+ cd spec/dummy && rake db:migrate RAILS_ENV=test && cd ../..
84
+ guard
85
+
86
+ = License
87
+
88
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,19 @@
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
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Cmor::Cms'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ Bundler::GemHelper.install_tasks
18
+
19
+ require 'rails/dummy/tasks'
@@ -0,0 +1 @@
1
+ //= require_tree ./application
@@ -0,0 +1,4 @@
1
+ $ ->
2
+ $("li[data_add_icon] a").each (index, element) ->
3
+ icon = $(element).parent().attr('data_add_icon')
4
+ $(element).prepend("<span class=\"glyphicon glyphicon-#{icon}\"></span>")
@@ -0,0 +1 @@
1
+ //= require cmor/cms/application
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require_tree ./application
3
+ */
@@ -0,0 +1,3 @@
1
+ /*
2
+ * = require cmor/cms/application
3
+ */
@@ -0,0 +1,54 @@
1
+ module Cmor
2
+ module Cms
3
+ class PageController < Cmor::Cms::Configuration.base_controller.constantize
4
+ include Cmor::Cms::ControllerExtensions::PageResolver
5
+ include Cmor::Cms::ControllerExtensions::PartialResolver
6
+
7
+ def respond
8
+ respond_to do |format|
9
+ format.html { render template: params[:page] }
10
+ format.txt { render template: params[:page], layout: false, formats: [:text] }
11
+ # format.pdf do
12
+ # output = render_to_string template: params[:page], formats: [:html, :pdf], layout: false
13
+ # self.response_body = WickedPdf.new.pdf_from_string(output)
14
+ # end if Gem::Specification.find_all_by_name('wicked_pdf').any?
15
+ end
16
+ end
17
+
18
+ module MissingTemplateConcern
19
+ extend ActiveSupport::Concern
20
+
21
+ included do
22
+ # avoid error 500 on missing template
23
+ rescue_from ActionView::MissingTemplate do
24
+ if params[:page] == 'home'
25
+ render_fallback_page
26
+ else
27
+ respond_to do |format|
28
+ format.html do
29
+ render(file: "#{Rails.root}/public/404", formats: [:html],
30
+ layout: false,
31
+ status: 404
32
+ )
33
+ end
34
+ format.xml { head :not_found }
35
+ format.any { head :not_found }
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def render_fallback_page
44
+ respond_to do |format|
45
+ format.html { render :fallback }
46
+ format.txt { render :fallback }
47
+ end
48
+ end
49
+ end
50
+
51
+ include MissingTemplateConcern
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,27 @@
1
+ module Cmor
2
+ module Cms
3
+ module Importers
4
+ class Navigation
5
+ def initialize(yaml, _option = {})
6
+ @navigations = nil
7
+ @yaml = YAML.load(yaml)
8
+ end
9
+
10
+ def build_navigations
11
+ navigations = []
12
+ @yaml.each do |navigation_data|
13
+ navigation = Cmor::Cms::Navigation.new(navigation_data)
14
+ navigations << navigation
15
+ end if @yaml.respond_to?(:each)
16
+ navigations
17
+ end
18
+
19
+ def navigations
20
+ @navigations ||= build_navigations
21
+ end
22
+
23
+ attr_reader :yaml
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,61 @@
1
+ module Cmor
2
+ module Cms
3
+ module Importers
4
+ class NavigationItem
5
+ def initialize(yaml, _option = {})
6
+ @navigation_items = nil
7
+ @yaml = YAML.load(yaml)
8
+ end
9
+
10
+ def navigation_items
11
+ @navigation_items ||= create_navigation_items
12
+ end
13
+
14
+ private
15
+
16
+ def create_navigation_items
17
+ built_navigation_items = []
18
+ @yaml.each do |navigation_locale, navigation|
19
+ navigation.each do |navigation_name, navigation_items_attributes|
20
+ n = find_or_create_navigation(navigation_locale, navigation_name)
21
+ built_navigation_items << create_navigation_items_for_navigation(n, navigation_items_attributes)
22
+ end if navigation_locale.respond_to?(:each)
23
+ end if @yaml.respond_to?(:each)
24
+ built_navigation_items.flatten
25
+ end
26
+
27
+ def create_navigation_items_for_navigation(navigation, navigation_items_attributes)
28
+ built_navigation_items = []
29
+ navigation_items_attributes.each do |navigation_item_attributes|
30
+ ni = create_navigation_item(navigation_item_attributes, navigation)
31
+ built_navigation_items << ni
32
+ end
33
+ built_navigation_items
34
+ end
35
+
36
+ def create_navigation_item(navigation_item_attributes, navigation)
37
+ subitems = navigation_item_attributes.delete('subitems')
38
+
39
+ ni = Cmor::Cms::NavigationItem.new(navigation_item_attributes)
40
+ ni.cmor_cms_navigation = navigation
41
+ ni.save!
42
+
43
+ subitems.each do |subitem_attributes|
44
+ subitem_attributes['parent'] = ni
45
+ create_navigation_item(subitem_attributes, navigation)
46
+ end if subitems.respond_to?(:each)
47
+
48
+ ni
49
+ end
50
+
51
+ def find_or_create_navigation(navigation_locale, navigation_name)
52
+ navigation = Cmor::Cms::Navigation.where(locale: navigation_locale, name: navigation_name).first
53
+ navigation = Cmor::Cms::Navigation.create!(locale: navigation_locale, name: navigation_name) if navigation.nil?
54
+ navigation
55
+ end
56
+
57
+ attr_reader :yaml
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,38 @@
1
+ module Cmor
2
+ module Cms
3
+ module Importers
4
+ class Page
5
+ def initialize(yaml, _option = {})
6
+ @pages = nil
7
+ @yaml = YAML.load(yaml)
8
+ end
9
+
10
+ def build_pages
11
+ pages = []
12
+ @yaml.each do |page_data|
13
+ navigation_items = extract_navigation_items(page_data.delete('navigation_items'))
14
+ page = Cmor::Cms::Page.new(page_data)
15
+ page.cmor_cms_navigation_item_ids = navigation_items.map(&:id)
16
+ pages << page
17
+ end if @yaml.respond_to?(:each)
18
+ pages
19
+ end
20
+
21
+ def extract_navigation_items(navigation_item_data)
22
+ navigation_items = []
23
+ navigation_item_data.each do |nid|
24
+ navigation = Cmor::Cms::Navigation.where(locale: nid['navigation_locale'], name: nid['navigation_name']).first
25
+ navigation_items << navigation.cmor_cms_navigation_items.where(name: nid['name']).first if navigation.respond_to?(:cmor_cms_navigation_items)
26
+ end
27
+ navigation_items
28
+ end
29
+
30
+ def pages
31
+ @pages ||= build_pages
32
+ end
33
+
34
+ attr_reader :yaml
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ module Cmor::Cms
2
+ class ContentBlock < ActiveRecord::Base
3
+ # associations
4
+ belongs_to :content_box
5
+ belongs_to :page
6
+
7
+ # validations
8
+ validates :body, presence: true
9
+
10
+ def content_box_name
11
+ content_box.name
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module Cmor::Cms
2
+ class ContentBox < ActiveRecord::Base
3
+ # associations
4
+ has_many :content_blocks
5
+
6
+ # validations
7
+ validates :name, presence: true,
8
+ uniqueness: true
9
+
10
+ delegate :count, to: :content_blocks, prefix: true
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ class Cmor::Cms::Navigation < ActiveRecord::Base
2
+ # associations
3
+ has_many :navigation_items,
4
+ dependent: :destroy
5
+
6
+ # validations
7
+ validates :locale, inclusion: I18n.available_locales.map(&:to_s),
8
+ allow_nil: true,
9
+ allow_blank: true
10
+ validates :name, presence: true,
11
+ uniqueness: { scope: [:locale] }
12
+
13
+ delegate :count, to: :navigation_items, prefix: true
14
+
15
+ def human
16
+ "#{name} (#{locale})"
17
+ end
18
+ end
@@ -0,0 +1,86 @@
1
+ require_dependency 'model/cmor/cms/navigation_item/properties_concern'
2
+
3
+ module Cmor::Cms
4
+ class NavigationItem < ActiveRecord::Base
5
+ include Model::Cmor::Cms::NavigationItem::PropertiesConcern
6
+
7
+ # associations
8
+ belongs_to :navigation,
9
+ optional: true
10
+ belongs_to :page,
11
+ optional: true
12
+
13
+ # awesome nested set
14
+ acts_as_nested_set dependent: :destroy, counter_cache: :children_count, scope: :navigation_id
15
+
16
+ # callbacks
17
+ before_validation :update_navigation_from_parent, if: proc { |ni| ni.child? }
18
+ before_validation :update_url_form_page, if: proc { |ni| ni.page.present? && ni.url.blank? }
19
+ after_save :update_children_navigations!
20
+
21
+ # default_scope
22
+ default_scope { order(:navigation_id, :lft) }
23
+
24
+ # validations
25
+ validates :key, presence: true
26
+ validates :name, presence: true
27
+ validates :url, presence: true
28
+ validates :navigation, presence: true, if: -> { parent.nil? }
29
+
30
+ def params_for_new_page
31
+ return {} if self.new_record?
32
+ match = url.scan(/(#{I18n.available_locales.join('|')})$/)
33
+ return { locale: match[0][0], pathname: '/', basename: 'home', title: name, navigation_item_ids: [to_param] } if match.size > 0
34
+ match = url.scan(/(#{I18n.available_locales.join('|')})(.*)\/(.*)/)
35
+ return {} unless match.first.respond_to?(:size) # && match.first.size != 3
36
+ params = match.first
37
+ return {} if params.size != 3
38
+ params[1] << '/' unless params[1].end_with?('/')
39
+ { locale: params[0], pathname: params[1], basename: params[2], title: name, navigation_item_ids: [to_param] }
40
+ end
41
+
42
+ def to_label
43
+ if depth > 0
44
+ "#{'&nbsp;' * depth} &#9654; #{name}".html_safe
45
+ else
46
+ name
47
+ end
48
+ end
49
+
50
+ def to_s
51
+ "#{navigation}: #{name}"
52
+ end
53
+
54
+ def update_navigation_from_parent!
55
+ update_navigation_from_parent
56
+ save!
57
+ end
58
+
59
+ def update_children_navigations!
60
+ descendants.map(&:"update_navigation_from_parent!")
61
+ end
62
+
63
+ def update_url_form_page!
64
+ update_url_form_page
65
+ save!
66
+ end
67
+
68
+ private
69
+
70
+ def build_url_from_page(locale, pathname, basename, is_home_page)
71
+ if is_home_page
72
+ "/#{locale}"
73
+ else
74
+ "/#{locale}#{pathname}#{basename}"
75
+ end
76
+ end
77
+
78
+ def update_navigation_from_parent
79
+ self.navigation = parent.navigation
80
+ end
81
+
82
+ def update_url_form_page
83
+ self.url = build_url_from_page(page.locale, page.pathname, page.basename, page.home_page?)
84
+ end
85
+ end
86
+ end