honey-cms 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/cms/pages_controller.rb +1 -1
- data/app/views/cms/pages/show.html.haml +3 -3
- data/lib/cms/helper.rb +14 -5
- data/lib/cms/page.rb +5 -2
- metadata +1 -1
@@ -1,3 +1,3 @@
|
|
1
|
-
.cms-page{class: "cms-#{@page}-page"}
|
2
|
-
= cms_page_area :"cms_#{@page}_page" do
|
3
|
-
%h1= @page.capitalize
|
1
|
+
.cms-page{class: "cms-#{@page.name}-page"}
|
2
|
+
= cms_page_area :"cms_#{@page.name}_page", @page.options do
|
3
|
+
%h1= @page.name.capitalize
|
data/lib/cms/helper.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
module CMS::Helper
|
4
|
+
def markdown text
|
5
|
+
Markdown.render(text).html_safe
|
6
|
+
end
|
7
|
+
|
4
8
|
def cms_file name, size = false
|
5
9
|
if file = CMS::FileUpload.find_by_name(name) then return file end
|
6
10
|
opts = {name: name}
|
@@ -24,15 +28,16 @@ module CMS::Helper
|
|
24
28
|
end
|
25
29
|
|
26
30
|
|
27
|
-
def cms_page_area name, &block
|
31
|
+
def cms_page_area name, options = {}, &block
|
28
32
|
page_area = if area = CMS::PageArea.find_by_name(name) then area else CMS::PageArea.new({name: name}, without_protection: true) end
|
33
|
+
options[:editable] = true unless options.key?(:editable)
|
29
34
|
|
30
|
-
if admin?
|
35
|
+
if admin? && options[:editable]
|
31
36
|
content_tag :div, role: 'html-editor' do
|
32
37
|
out = content_tag(:div, class: 'cms-page-area', role: 'display') do
|
33
38
|
display = ''.html_safe
|
34
39
|
display << cms_page_area_edit_link if admin?
|
35
|
-
display << render_cms_page_area_content(page_area, &block)
|
40
|
+
display << render_cms_page_area_content(page_area, options, &block)
|
36
41
|
end
|
37
42
|
|
38
43
|
out << content_tag(:div, role: 'editor') do
|
@@ -45,14 +50,14 @@ module CMS::Helper
|
|
45
50
|
end
|
46
51
|
else
|
47
52
|
content_tag :div, class: 'cms-page-area' do
|
48
|
-
render_cms_page_area_content(page_area, &block)
|
53
|
+
render_cms_page_area_content(page_area, options, &block)
|
49
54
|
end
|
50
55
|
end
|
51
56
|
rescue Exception => e
|
52
57
|
if Rails.env.production? then '' else raise e end
|
53
58
|
end
|
54
59
|
|
55
|
-
def render_cms_page_area_content page_area, &block
|
60
|
+
def render_cms_page_area_content page_area, options = {}, &block
|
56
61
|
if page_area.content.present? && !page_area.default
|
57
62
|
content = page_area.content
|
58
63
|
elsif block_given?
|
@@ -61,6 +66,10 @@ module CMS::Helper
|
|
61
66
|
page_area.save!
|
62
67
|
end
|
63
68
|
|
69
|
+
if options[:format].try(:to_s) == 'markdown'
|
70
|
+
content = markdown(content)
|
71
|
+
end
|
72
|
+
|
64
73
|
content_tag(:div, class: 'content') do
|
65
74
|
cms_content_parse(content) if content.present?
|
66
75
|
end
|
data/lib/cms/page.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
class CMS::Page
|
2
|
-
attr_reader :route, :options
|
2
|
+
attr_reader :name, :route, :options
|
3
3
|
|
4
4
|
def initialize route, options
|
5
|
-
@options = options
|
5
|
+
@options = options.reverse_merge({
|
6
|
+
editable: true
|
7
|
+
})
|
8
|
+
@name = route
|
6
9
|
@route = (options[:route] || route).dup
|
7
10
|
end
|
8
11
|
|