cmor_cms 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
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,26 @@
1
+ module ActionView::Template::Handlers
2
+ class Textile
3
+ class_attribute :default_format
4
+ self.default_format = Mime[:html]
5
+
6
+ def erb_handler
7
+ @@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
8
+ end
9
+
10
+ # def call(template, source)
11
+ # compiled_source = erb_handler.call(template, source)
12
+ # "RedCloth.new(begin;#{compiled_source};end).to_html.html_safe"
13
+ # end
14
+ if Rails.version < '6.0.0.beta2'
15
+ def call(template)
16
+ compiled_source = erb_handler.call(template)
17
+ "RedCloth.new(begin;#{compiled_source};end).to_html.html_safe"
18
+ end
19
+ else
20
+ def call(template, source)
21
+ compiled_source = erb_handler.call(template, source)
22
+ "RedCloth.new(begin;#{compiled_source};end).to_html.html_safe"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,36 @@
1
+ module Cmor
2
+ module Cms
3
+ # Usage:
4
+ #
5
+ # # app/controllers/application_controller.rb
6
+ # class ApplicationController < ActionController::Base
7
+ # view_helper Cmor::Cms::ApplicationViewHelper, as: :cms_helper
8
+ # end
9
+ #
10
+ class ApplicationViewHelper < Rao::ViewHelper::Base
11
+ def title
12
+ c.content_for(:title)
13
+ end
14
+
15
+ def meta_description
16
+ "<meta name=\"description\" content=\"#{c.content_for(:meta_description)}\">"
17
+ end
18
+
19
+ def link_to_top
20
+ c.render partial: '/cmor/cms/link_to_top'
21
+ end
22
+
23
+ def is_page?
24
+ params[:action] == 'respond' && params.has_key?(:page)
25
+ end
26
+
27
+ def current_page?(page)
28
+ cms_page? && params[:page].to_s == page.to_s
29
+ end
30
+
31
+ def current_page
32
+ cms_page? ? params[:page].to_s : nil
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,87 @@
1
+ module Cmor
2
+ module Cms
3
+ # Usage:
4
+ #
5
+ # # app/controllers/application_controller.rb
6
+ # class ApplicationController < ActionController::Base
7
+ # view_helper Cmor::Cms::NavigationViewHelper, as: :cms_navigation_helper
8
+ # end
9
+ #
10
+ class NavigationViewHelper < Rao::ViewHelper::Base
11
+ # Example:
12
+ #
13
+ # # This will render a bootstrap 4 compatible navigation
14
+ # = cms_navigation_helper(self).render(
15
+ # :main,
16
+ # renderer: :list,
17
+ # container_css_class: 'navbar-nav',
18
+ # selected_class: 'active',
19
+ # item_html: { class: 'nav-item' },
20
+ # link_html: { class: 'nav-link' }
21
+ # )
22
+ #
23
+ def render(name, options = {})
24
+ options.reverse_merge!(
25
+ renderer: :bootstrap,
26
+ expand_all: true,
27
+ level: 1,
28
+ selected_class: nil,
29
+ item_html: {},
30
+ link_html: {}
31
+ )
32
+
33
+ level = options.delete(:level)
34
+ expand_all = options.delete(:expand_all)
35
+ container_css_class = options.delete(:container_css_class)
36
+ renderer = options.delete(:renderer)
37
+ selected_class = options.delete(:selected_class)
38
+ item_html = options.delete(:item_html)
39
+ link_html = options.delete(:link_html)
40
+
41
+ level_as_array = (level).is_a?(Range) ? level.to_a : [level]
42
+
43
+ navigation = Cmor::Cms::Navigation.where(name: name.to_s, locale: I18n.locale.to_s).first
44
+ if navigation.nil? && (locale = Cmor::Cms::Configuration.navigation_locale_fallback.call(name, I18n.locale))
45
+ navigation = Cmor::Cms::Navigation.where(name: name.to_s, locale: locale).first
46
+ end
47
+ unless navigation
48
+ return I18n.t('cmor.cms.navigation.messages.not_found', lang: I18n.locale.to_s, name: name.to_s)
49
+ end
50
+
51
+ roots = navigation.cmor_cms_navigation_items.roots.all
52
+ if roots.empty?
53
+ return I18n.t('cmor.cms.navigation.messages.empty', lang: I18n.locale.to_s, name: name)
54
+ end
55
+
56
+ c.render_navigation(level: level, expand_all: expand_all, renderer: renderer) do |navigation|
57
+ navigation.dom_class = container_css_class
58
+ navigation.selected_class = selected_class unless selected_class.nil?
59
+ roots.each do |navigation_item|
60
+ build_navigation_item(navigation, navigation_item, container_css_class, item_html, link_html)
61
+ end
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def build_navigation_item(navigation, item, container_css_class, item_html = {}, link_html = {})
68
+ options = {}
69
+ options[:highlights_on] = /#{item.highlights_on}/ if item.highlights_on.present?
70
+ options[:html] = item.li_attributes.marshal_dump.delete_if { |_key, value| value.blank? }
71
+
72
+ options.reverse_merge!(html: item_html.dup, link_html: link_html)
73
+
74
+ navigation.dom_class = container_css_class
75
+ if item.children.present?
76
+ navigation.item(item.key, item.name, item.url, options) do |sub_navigation|
77
+ item.children.each do |sub_item|
78
+ build_navigation_item(sub_navigation, sub_item, container_css_class, item_html, link_html)
79
+ end
80
+ end
81
+ else
82
+ navigation.item item.key, item.name, item.url, options
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,34 @@
1
+ module Cmor
2
+ module Cms
3
+ # Usage:
4
+ #
5
+ # # app/controllers/application_controller.rb
6
+ # class ApplicationController < ActionController::Base
7
+ # view_helper Cmor::Cms::PageViewHelper, as: :cms_page_helper
8
+ # end
9
+ #
10
+ class PageViewHelper < Rao::ViewHelper::Base
11
+ def is_page?
12
+ c.params[:action] == 'respond' && page_param.present?
13
+ end
14
+
15
+ def current?(page)
16
+ is_page? && page_param.to_s == page.to_s
17
+ end
18
+
19
+ def current
20
+ is_page? ? page_param.to_s : nil
21
+ end
22
+
23
+ def home?
24
+ current?(:home)
25
+ end
26
+
27
+ private
28
+
29
+ def page_param
30
+ c.params[:page]
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ <%= content_tag(:div, class: 'pull-right') do %>
2
+ <%= link_to('#top', id: 'top-link', class: 'btn btn-primary') do %>
3
+ <%= content_tag(:i, nil, class: 'glyphicon glyphicon-arrow-up') %>
4
+ <% end %>
5
+ <% end %>
@@ -0,0 +1,2 @@
1
+ <% content_for(:title) { 'Fallback' } %>
2
+ <h1>Fallback</h1>
@@ -0,0 +1 @@
1
+ Fallback
@@ -0,0 +1 @@
1
+ Rails.application.config.assets.precompile += %w( cmor_cms.css cmor_cms.js )
@@ -0,0 +1 @@
1
+ Mime::Type.register "text/plain", :txt
@@ -0,0 +1 @@
1
+ SimpleNavigation.config_file_paths << Cmor::Cms::Engine.root.join(*%w(config))
@@ -0,0 +1,3 @@
1
+ Rails.application.config.to_prepare do
2
+ ::ActionView::Template.register_template_handler :textile, ::ActionView::Template::Handlers::Textile.new
3
+ end
@@ -0,0 +1,140 @@
1
+ de:
2
+ activerecord:
3
+ models:
4
+ cmor/cms/content_block:
5
+ one: Content Block
6
+ other: Content Blöcke
7
+ cmor/cms/content_box:
8
+ one: Content Box
9
+ other: Content Boxen
10
+ cmor/cms/navigation:
11
+ one: Navigation
12
+ other: Navigationen
13
+ cmor/cms/navigation_item:
14
+ one: Navigationseintrag
15
+ other: Navigationseinträge
16
+ cmor/cms/page:
17
+ one: Seite
18
+ other: Seiten
19
+ cmor/cms/partial:
20
+ one: Fragment
21
+ other: Fragmente
22
+ cmor/cms/template:
23
+ one: Vorlage
24
+ other: Vorlagen
25
+ attributes:
26
+ cmor/cms/content_block:
27
+ id: ID
28
+ body: Inhalt
29
+ page: Seite
30
+ page_id: Seite
31
+ content_box: Content Box
32
+ content_box_id: Content Box
33
+ created_at: Erstellt am
34
+ updated_at: Aktualisiert am
35
+ cmor/cms/content_box:
36
+ id: ID
37
+ name: Name
38
+ body: Inhalt
39
+ content_blocks: Content Blöcke
40
+ content_blocks_count: Content Blöcke
41
+ created_at: Erstellt am
42
+ updated_at: Aktualisiert am
43
+ cmor/cms/navigation:
44
+ id: ID
45
+ created_at: Erstellt am
46
+ cmor_cms_navigation_items: Navigationseinträge
47
+ cmor_cms_navigation_items_count: Navigationseinträge
48
+ locale: Sprache
49
+ name: Name
50
+ slug: Freundliche ID
51
+ updated_at: Aktualisiert am
52
+ cmor/cms/navigation_item:
53
+ id: ID
54
+ children_count: Unterelemente
55
+ data_add_icon: Symbol
56
+ depth: Baumtiefe
57
+ navigation: Navigation
58
+ navigation_id: Navigation
59
+ page: Seite
60
+ page_id: Seite
61
+ highlights_on: Hervorgehoben bei
62
+ key: Schlüssel
63
+ lft: Links
64
+ li_attributes: 'Listen-Element Attribute'
65
+ name: Name
66
+ options: Optionen
67
+ parent: Untereintrag von
68
+ parent_id: Untereintrag von
69
+ properties: Eigenschaften
70
+ rgt: Rechts
71
+ slug: Freundliche ID
72
+ url: Ziel-URL
73
+ created_at: Erstellt am
74
+ updated_at: Aktualisiert am
75
+ cmor/cms/page:
76
+ id: ID
77
+ basename: Name
78
+ body: Inhalt
79
+ cmor_cms_folder_id: Ordner
80
+ cmor_cms_folder: Ordner
81
+ cmor_cms_navigation_items: Verlinkt von
82
+ cmor_cms_navigation_item_ids: Verlinkt von
83
+ filename: Dateiname
84
+ format: Format
85
+ handler: Handler
86
+ layout: Layout
87
+ locale: Sprache
88
+ meta_description: Meta Beschreibung
89
+ path_and_filename: Dateipfad
90
+ pathname: Pfad
91
+ title: Titel
92
+ created_at: Erstellt am
93
+ updated_at: Aktualisiert am
94
+ cmor/cms/partial:
95
+ id: ID
96
+ basename: Name
97
+ body: Inhalt
98
+ cmor_cms_folder_id: Ordner
99
+ cmor_cms_folder: Ordner
100
+ filename: Dateiname
101
+ format: Format
102
+ handler: Handler
103
+ layout: Layout
104
+ locale: Sprache
105
+ pathname: Pfad
106
+ created_at: Erstellt am
107
+ updated_at: Aktualisiert am
108
+ cmor/cms/template:
109
+ id: ID
110
+ basename: Name
111
+ body: Inhalt
112
+ cmor_cms_folder_id: Ordner
113
+ cmor_cms_folder: Ordner
114
+ filename: Dateiname
115
+ format: Format
116
+ handler: Handler
117
+ layout: Layout
118
+ locale: Sprache
119
+ pathname: Pfad
120
+ created_at: Erstellt am
121
+ updated_at: Aktualsiert am
122
+ classes:
123
+ cmor/cms/add_homepages_service: 'Dienst zum hinzufügen von Homepages'
124
+ cmor/cms/import_partials_service: 'Dienst zum importieren von Fragmenten'
125
+ cmor:
126
+ cms:
127
+ active_admin:
128
+ menu: CMS
129
+ navigation:
130
+ messages:
131
+ empty: Navigation %{name} (%{lang}) ist leer
132
+ not_found: Navigation %{name} (%{lang}) nicht gefunden
133
+ resources:
134
+ cmor_cms_folders: ordner
135
+ cmor_cms_navigations: navigationen
136
+ cmor_cms_navigation_items: navigationseintraege
137
+ pages: seiten
138
+ partials: fragmente
139
+ templates: vorlagen
140
+
@@ -0,0 +1,140 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ cmor/cms/content_block:
5
+ one: Content block
6
+ other: Content blocks
7
+ cmor/cms/content_box:
8
+ one: Content box
9
+ other: Content boxes
10
+ cmor/cms/navigation:
11
+ one: Navigation
12
+ other: Navigations
13
+ cmor/cms/navigation_item:
14
+ one: Navigation item
15
+ other: Navigation items
16
+ cmor/cms/page:
17
+ one: Page
18
+ other: Pages
19
+ cmor/cms/partial:
20
+ one: Partial
21
+ other: Partials
22
+ cmor/cms/template:
23
+ one: Template
24
+ other: Templates
25
+ attributes:
26
+ cmor/cms/content_block:
27
+ id: ID
28
+ body: Body
29
+ page: Page
30
+ page_id: Page
31
+ content_box: Content box
32
+ content_box_id: Content box
33
+ created_at: Created at
34
+ updated_at: Updated at
35
+ cmor/cms/content_box:
36
+ id: ID
37
+ name: Name
38
+ body: Body
39
+ content_blocks: Content blocks
40
+ content_blocks_count: Content blocks
41
+ created_at: Created at
42
+ updated_at: updated at
43
+ cmor/cms/navigation:
44
+ id: ID
45
+ navigation_items: Navigation items
46
+ navigation_items_count: Navigation items
47
+ locale: Language
48
+ name: Name
49
+ slug: Slug
50
+ created_at: Created at
51
+ updated_at: updated at
52
+ cmor/cms/navigation_item:
53
+ id: ID
54
+ children_count: Subitems
55
+ data_add_icon: Icon
56
+ depth: Tree depth
57
+ navigation: Nvigation
58
+ navigation_id: Navigation
59
+ page: Page
60
+ page_id: Page
61
+ highlights_on: Highlights on
62
+ key: Key
63
+ lft: Left
64
+ li_attributes: 'List-element attributes'
65
+ name: Name
66
+ options: Options
67
+ parent: Parent
68
+ parent_id: Parent
69
+ properties: Properties
70
+ rgt: Right
71
+ slug: Slug
72
+ url: Target url
73
+ created_at: Created at
74
+ updated_at: Updated at
75
+ cmor/cms/page:
76
+ id: ID
77
+ basename: Name
78
+ body: Body
79
+ cmor_cms_folder_id: Folder
80
+ cmor_cms_folder: Folder
81
+ cmor_cms_navigation_items: Navigation items
82
+ cmor_cms_navigation_item_ids: Navigation items
83
+ filename: Filename
84
+ format: Format
85
+ handler: Handler
86
+ layout: Layout
87
+ locale: Language
88
+ meta_description: Meta description
89
+ path_and_filename: Filepath
90
+ pathname: Path
91
+ title: Title
92
+ created_at: Created at
93
+ updated_at: Updated at
94
+ cmor/cms/partial:
95
+ id: ID
96
+ basename: Name
97
+ body: Body
98
+ cmor_cms_folder_id: Folder
99
+ cmor_cms_folder: Folder
100
+ filename: Filename
101
+ format: Format
102
+ handler: Handler
103
+ layout: Layout
104
+ locale: Language
105
+ pathname: Path
106
+ created_at: Created at
107
+ updated_at: Updated at
108
+ cmor/cms/template:
109
+ id: ID
110
+ basename: Name
111
+ body: Body
112
+ cmor_cms_folder_id: Folder
113
+ cmor_cms_folder: Folder
114
+ filename: Filename
115
+ format: Format
116
+ handler: Handler
117
+ layout: Layout
118
+ locale: Language
119
+ pathname: Path
120
+ created_at: Created at
121
+ updated_at: Updated at
122
+ classes:
123
+ cmor/cms/add_homepages_service: 'Add homepages service'
124
+ cmor/cms/import_partials_service: 'Import partials service'
125
+ cmor:
126
+ cms:
127
+ active_admin:
128
+ menu: CMS
129
+ navigation:
130
+ messages:
131
+ empty: Navigation %{name} (%{lang}) is empty
132
+ not_found: Could not find navigation %{name} (%{lang})
133
+ resources:
134
+ cmor_cms_folders: folders
135
+ cmor_cms_navigations: navigations
136
+ cmor_cms_navigation_items: navigation_items
137
+ pages: pages
138
+ partials: partials
139
+ templates: templates
140
+