comatose-rubyisbeautiful 3.0.0
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.
- data/CHANGELOG +198 -0
- data/Gemfile +29 -0
- data/Gemfile.lock +130 -0
- data/INSTALL +14 -0
- data/LICENSE +20 -0
- data/Manifest +188 -0
- data/README +0 -0
- data/README.markdown +113 -0
- data/Rakefile +5 -0
- data/SPECS +61 -0
- data/app/controllers/application_controller.rb +3 -0
- data/app/controllers/comatose/admin_controller.rb +425 -0
- data/app/controllers/comatose/application_controller.rb +30 -0
- data/app/controllers/comatose/base_controller.rb +167 -0
- data/app/helpers/application_helper.rb +2 -0
- data/app/helpers/comatose/admin_helper.rb +78 -0
- data/app/helpers/comatose/application_helper.rb +2 -0
- data/app/helpers/comatose/base_helper.rb +5 -0
- data/app/models/comatose/page.rb +166 -0
- data/app/views/comatose/admin/_form.html.erb +108 -0
- data/app/views/comatose/admin/_page_list_item.html.erb +62 -0
- data/app/views/comatose/admin/delete.html.erb +18 -0
- data/app/views/comatose/admin/edit.html.erb +5 -0
- data/app/views/comatose/admin/index.html.erb +34 -0
- data/app/views/comatose/admin/new.html.erb +5 -0
- data/app/views/comatose/admin/reorder.html.erb +30 -0
- data/app/views/comatose/admin/versions.html.erb +40 -0
- data/app/views/layouts/application.html.erb +14 -0
- data/app/views/layouts/comatose/admin.html.erb +44 -0
- data/app/views/layouts/comatose/base.html.erb +14 -0
- data/comatose-rubyisbeautiful.gemspec +65 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +26 -0
- data/config/environments/production.rb +49 -0
- data/config/environments/test.rb +35 -0
- data/config/locales/en.yml +5 -0
- data/config.ru +4 -0
- data/db/seeds.rb +11 -0
- data/lib/comatose/configuration.rb +87 -0
- data/lib/comatose/drop.rb +45 -0
- data/lib/comatose/engine.rb +28 -0
- data/lib/comatose/filters/inline_filter.rb +15 -0
- data/lib/comatose/filters/timeago_filter.rb +14 -0
- data/lib/comatose/filters/translation_filter.rb +11 -0
- data/lib/comatose/locale_constraint.rb +15 -0
- data/lib/comatose/logger.rb +10 -0
- data/lib/comatose/page_wrapper.rb +147 -0
- data/lib/comatose/processing_context.rb +103 -0
- data/lib/comatose/routes.rb +70 -0
- data/lib/comatose/tasks/admin.rb +57 -0
- data/lib/comatose/tasks/data.rb +79 -0
- data/lib/comatose/tasks/setup.rb +118 -0
- data/lib/comatose/text_filters.rb +148 -0
- data/lib/comatose/version.rb +9 -0
- data/lib/comatose.rb +88 -0
- data/lib/generators/comatose/USAGE +7 -0
- data/lib/generators/comatose/comatose_generator.rb +37 -0
- data/lib/generators/comatose/templates/comatose.rb +33 -0
- data/lib/generators/comatose/templates/migration.erb +32 -0
- data/lib/generators/comatose/templates/seeds.erb +2 -0
- data/lib/support/class_options.rb +36 -0
- data/lib/support/inline_rendering.rb +48 -0
- data/lib/support/route_mapper.rb +51 -0
- data/lib/tasks/comatose.rake +9 -0
- data/lib/text_filters/markdown.rb +14 -0
- data/lib/text_filters/markdown_smartypants.rb +15 -0
- data/lib/text_filters/none.rb +8 -0
- data/lib/text_filters/rdoc.rb +13 -0
- data/lib/text_filters/simple.rb +8 -0
- data/lib/text_filters/textile.rb +15 -0
- data/public/404.html +26 -0
- data/public/422.html +26 -0
- data/public/500.html +26 -0
- data/public/favicon.ico +0 -0
- data/public/images/comatose/collapsed.gif +0 -0
- data/public/images/comatose/expanded.gif +0 -0
- data/public/images/comatose/no-children.gif +0 -0
- data/public/images/comatose/page.gif +0 -0
- data/public/images/comatose/rails.png +0 -0
- data/public/images/comatose/spinner.gif +0 -0
- data/public/images/comatose/title-hover-bg.gif +0 -0
- data/public/javascripts/comatose/admin.js +406 -0
- data/public/javascripts/comatose/application.js +2 -0
- data/public/javascripts/comatose/dragdrop.js +974 -0
- data/public/javascripts/editor.js +452 -0
- data/public/javascripts/jquery/GPL-LICENSE.txt +278 -0
- data/public/javascripts/jquery/MIT-LICENSE.txt +20 -0
- data/public/javascripts/jquery/README +67 -0
- data/public/javascripts/jquery/jquery.js +11 -0
- data/public/javascripts/jquery/jquery.ui.draggable.js +1 -0
- data/public/javascripts/jquery/jquery.ui.js +1 -0
- data/public/javascripts/jquery/jquery.ui.resizable.js +1 -0
- data/public/javascripts/jquery/jquery.ui.sortable.js +1 -0
- data/public/javascripts/wymeditor/iframe/default/lbl-blockquote.png +0 -0
- data/public/javascripts/wymeditor/iframe/default/lbl-h1.png +0 -0
- data/public/javascripts/wymeditor/iframe/default/lbl-h2.png +0 -0
- data/public/javascripts/wymeditor/iframe/default/lbl-h3.png +0 -0
- data/public/javascripts/wymeditor/iframe/default/lbl-h4.png +0 -0
- data/public/javascripts/wymeditor/iframe/default/lbl-h5.png +0 -0
- data/public/javascripts/wymeditor/iframe/default/lbl-h6.png +0 -0
- data/public/javascripts/wymeditor/iframe/default/lbl-p.png +0 -0
- data/public/javascripts/wymeditor/iframe/default/lbl-pre.png +0 -0
- data/public/javascripts/wymeditor/iframe/default/wymiframe.css +90 -0
- data/public/javascripts/wymeditor/iframe/default/wymiframe.html +26 -0
- data/public/javascripts/wymeditor/jquery.wymeditor.js +4688 -0
- data/public/javascripts/wymeditor/jquery.wymeditor.min.js +1 -0
- data/public/javascripts/wymeditor/jquery.wymeditor.pack.js +1 -0
- data/public/javascripts/wymeditor/lang/bg.js +45 -0
- data/public/javascripts/wymeditor/lang/ca.js +45 -0
- data/public/javascripts/wymeditor/lang/cs.js +45 -0
- data/public/javascripts/wymeditor/lang/cy.js +45 -0
- data/public/javascripts/wymeditor/lang/de.js +45 -0
- data/public/javascripts/wymeditor/lang/en.js +45 -0
- data/public/javascripts/wymeditor/lang/es.js +45 -0
- data/public/javascripts/wymeditor/lang/fa.js +46 -0
- data/public/javascripts/wymeditor/lang/fi.js +44 -0
- data/public/javascripts/wymeditor/lang/fr.js +45 -0
- data/public/javascripts/wymeditor/lang/gl.js +45 -0
- data/public/javascripts/wymeditor/lang/he.js +45 -0
- data/public/javascripts/wymeditor/lang/hr.js +45 -0
- data/public/javascripts/wymeditor/lang/hu.js +45 -0
- data/public/javascripts/wymeditor/lang/it.js +45 -0
- data/public/javascripts/wymeditor/lang/nb.js +45 -0
- data/public/javascripts/wymeditor/lang/nl.js +45 -0
- data/public/javascripts/wymeditor/lang/nn.js +45 -0
- data/public/javascripts/wymeditor/lang/pl.js +45 -0
- data/public/javascripts/wymeditor/lang/pt-br.js +45 -0
- data/public/javascripts/wymeditor/lang/pt.js +45 -0
- data/public/javascripts/wymeditor/lang/ru.js +45 -0
- data/public/javascripts/wymeditor/lang/sv.js +45 -0
- data/public/javascripts/wymeditor/lang/tr.js +45 -0
- data/public/javascripts/wymeditor/lang/zh_cn.js +47 -0
- data/public/javascripts/wymeditor/plugins/embed/jquery.wymeditor.embed.js +52 -0
- data/public/javascripts/wymeditor/plugins/fullscreen/icon_fullscreen.gif +0 -0
- data/public/javascripts/wymeditor/plugins/fullscreen/jquery.wymeditor.fullscreen.js +127 -0
- data/public/javascripts/wymeditor/plugins/hovertools/jquery.wymeditor.hovertools.js +57 -0
- data/public/javascripts/wymeditor/plugins/resizable/jquery.wymeditor.resizable.js +91 -0
- data/public/javascripts/wymeditor/plugins/resizable/readme.txt +124 -0
- data/public/javascripts/wymeditor/plugins/tidy/README +19 -0
- data/public/javascripts/wymeditor/plugins/tidy/jquery.wymeditor.tidy.js +82 -0
- data/public/javascripts/wymeditor/plugins/tidy/tidy.php +36 -0
- data/public/javascripts/wymeditor/plugins/tidy/wand.png +0 -0
- data/public/javascripts/wymeditor/skins/compact/icons.png +0 -0
- data/public/javascripts/wymeditor/skins/compact/skin.css +134 -0
- data/public/javascripts/wymeditor/skins/compact/skin.js +35 -0
- data/public/javascripts/wymeditor/skins/default/icons.png +0 -0
- data/public/javascripts/wymeditor/skins/default/skin.css +133 -0
- data/public/javascripts/wymeditor/skins/default/skin.js +40 -0
- data/public/javascripts/wymeditor/skins/minimal/images/bg.header.gif +0 -0
- data/public/javascripts/wymeditor/skins/minimal/images/bg.selector.silver.gif +0 -0
- data/public/javascripts/wymeditor/skins/minimal/images/bg.wymeditor.png +0 -0
- data/public/javascripts/wymeditor/skins/minimal/images/icons.silver.gif +0 -0
- data/public/javascripts/wymeditor/skins/minimal/skin.css +131 -0
- data/public/javascripts/wymeditor/skins/minimal/skin.js +30 -0
- data/public/javascripts/wymeditor/skins/silver/COPYING +674 -0
- data/public/javascripts/wymeditor/skins/silver/README +27 -0
- data/public/javascripts/wymeditor/skins/silver/images/bg.header.gif +0 -0
- data/public/javascripts/wymeditor/skins/silver/images/bg.selector.silver.gif +0 -0
- data/public/javascripts/wymeditor/skins/silver/images/bg.wymeditor.png +0 -0
- data/public/javascripts/wymeditor/skins/silver/images/icons.silver.gif +0 -0
- data/public/javascripts/wymeditor/skins/silver/skin.css +297 -0
- data/public/javascripts/wymeditor/skins/silver/skin.js +61 -0
- data/public/javascripts/wymeditor/skins/twopanels/icons.png +0 -0
- data/public/javascripts/wymeditor/skins/twopanels/skin.css +134 -0
- data/public/javascripts/wymeditor/skins/twopanels/skin.js +39 -0
- data/public/javascripts/wymeditor/skins/wymeditor_icon.png +0 -0
- data/public/javascripts/wymeditor.tar +0 -0
- data/public/robots.txt +5 -0
- data/public/stylesheets/comatose/admin.css +488 -0
- data/public/stylesheets/comatose/base.css +9 -0
- data/spec/controllers/comatose/base_controller_spec.rb +14 -0
- data/spec/controllers/foos_controller_spec.rb +5 -0
- data/spec/helpers/foos_helper_spec.rb +15 -0
- data/spec/routing/base_routing_spec.rb +12 -0
- data/spec/spec_helper.rb +27 -0
- data/test/behaviors.rb +106 -0
- data/test/fixtures/comatose_pages.yml +96 -0
- data/test/functional/comatose_admin_controller_test.rb +114 -0
- data/test/functional/comatose_controller_test.rb +45 -0
- data/test/integration/comatose_routing_test.rb +17 -0
- data/test/javascripts/test.html +26 -0
- data/test/javascripts/test_runner.js +307 -0
- data/test/old_test_helper.rb +43 -0
- data/test/performance/browsing_test.rb +9 -0
- data/test/test_helper.rb +13 -0
- data/test/unit/class_options_test.rb +52 -0
- data/test/unit/comatose_page_test.rb +128 -0
- data/test/unit/processing_context_test.rb +108 -0
- data/test/unit/text_filters_test.rb +52 -0
- data.tar.gz.sig +1 -0
- metadata +379 -0
- metadata.gz.sig +0 -0
@@ -0,0 +1,147 @@
|
|
1
|
+
# Giving direct access to the AR model is disconcerting, so this wraps the AR
|
2
|
+
# Model to prevent access to certain, destructive behavior
|
3
|
+
module Comatose
|
4
|
+
class PageWrapper
|
5
|
+
|
6
|
+
@@allowed_methods = %w( id full_path uri slug keywords title to_html filter_type author updated_at created_at )
|
7
|
+
@@custom_methods = %w( link content parent next previous children rchildren first_child last_child has_keyword current_user )
|
8
|
+
|
9
|
+
attr_accessor :page, :current_user
|
10
|
+
#private :page
|
11
|
+
|
12
|
+
def initialize(page, locals={}, system={})
|
13
|
+
@current_user = system[:current_user]
|
14
|
+
@page = page
|
15
|
+
@keyword_lst = []
|
16
|
+
@keyword_hsh = {}
|
17
|
+
unless page.nil?
|
18
|
+
@keyword_lst = (page.keywords || '').downcase.split(',').map{ |k| k.strip }
|
19
|
+
@keyword_lst.each { |kw| @keyword_hsh[kw] = true }
|
20
|
+
end
|
21
|
+
@locals = locals
|
22
|
+
rescue => e
|
23
|
+
Comatose.logger.debug e.message
|
24
|
+
Comatose.logger.debug e.backtrace.join("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
def has_keyword?(keyword)
|
30
|
+
@page.has_keyword?(keyword)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def has_keyword
|
35
|
+
@keyword_hsh
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def next
|
40
|
+
@next_page ||= begin
|
41
|
+
if @page.lower_item.nil?
|
42
|
+
nil
|
43
|
+
else
|
44
|
+
Comatose::PageWrapper.new( @page.lower_item )
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
def previous
|
51
|
+
@prev_page ||= begin
|
52
|
+
if @page.higher_item.nil?
|
53
|
+
nil
|
54
|
+
else
|
55
|
+
Comatose::PageWrapper.new( @page.higher_item )
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def first_child
|
62
|
+
children.first
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def def last_child
|
67
|
+
children.last
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
# Generates a link to this page... You can pass in the link text,
|
72
|
+
# otherwise it will default to the page title.
|
73
|
+
def link(title=nil)
|
74
|
+
title = @page.title if title.nil?
|
75
|
+
TextFilters[@page.filter_type].create_link(title, @page.uri)
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
def content
|
80
|
+
@page.to_html( @locals )
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def parent
|
85
|
+
@parent ||= begin
|
86
|
+
if @page.parent.nil?
|
87
|
+
nil
|
88
|
+
else
|
89
|
+
Comatose::PageWrapper.new( @page.parent )
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def children
|
96
|
+
# Cache the results so that you can have multiple calls to #children without a penalty
|
97
|
+
@children ||= @page.children.to_a.collect {|child| Comatose::PageWrapper.new( child, @locals )}
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
# Children, in reverse order
|
102
|
+
def rchildren
|
103
|
+
children.reverse
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
def [](key)
|
108
|
+
Comatose.logger.debug "using [] to find key: #{key}"
|
109
|
+
if @@allowed_methods.include? key.to_s #or page.attributes.has_key? key.to_s
|
110
|
+
page.send(key)
|
111
|
+
elsif @@custom_methods.include? key
|
112
|
+
self.send(key.to_sym)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
def has_key?(key)
|
118
|
+
@@allowed_methods.include? key or @@custom_methods.include? key
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
def to_s
|
123
|
+
@page.title
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
def to_liquid
|
128
|
+
self
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
def method_missing(method_id, *args)
|
133
|
+
#Comatose.logger.debug "Looking for method: #{method_id} (#{method_id.class.to_s}) in [#{@@allowed_methods.join(', ')}] or [#{page.attributes.keys.join(', ')}]"
|
134
|
+
if @@allowed_methods.include? method_id.to_s or page.attributes.has_key? method_id.to_s
|
135
|
+
#Comatose.logger.debug "sending method_id to page"
|
136
|
+
page_value = page.send(method_id, *args)
|
137
|
+
#Comatose.logger.debug "page returned: #{page_value}"
|
138
|
+
return page_value
|
139
|
+
else
|
140
|
+
# Access nazi says: NO ACCESS FOR YOU!!
|
141
|
+
# but he says it silently...
|
142
|
+
Comatose.logger.debug("PageWrapper#method_missing: could not find #{method_id}")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# This is the rendering context object you have access to in text processing...
|
2
|
+
module Comatose
|
3
|
+
class ProcessingContext < Hash
|
4
|
+
@@supported_methods = %w( page include current_user )
|
5
|
+
|
6
|
+
attr_accessor :locals, :page, :current_user, :system
|
7
|
+
|
8
|
+
|
9
|
+
def initialize(page, params={})
|
10
|
+
params = params.stringify_keys rescue params
|
11
|
+
#Comatose.logger.debug("params in ProcessingContext: #{params}")
|
12
|
+
@system = params.delete('system') || {}
|
13
|
+
@current_user = @system['current_user']
|
14
|
+
@locals = params
|
15
|
+
@page = Comatose::PageWrapper.new(page, @locals, @system)
|
16
|
+
#rescue => e
|
17
|
+
# Comatose.logger.debug "ProcessingContext: initialize: #{e.message}"
|
18
|
+
# Comatose.logger.debug e.backtrace.join("\n")
|
19
|
+
# raise e
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
#def include(path, locals={})
|
24
|
+
# begin
|
25
|
+
# page = Page.find_by_path(path)
|
26
|
+
# page.to_html(self[:locals].merge(locals) )
|
27
|
+
# rescue
|
28
|
+
# "<p>Page at <tt>#{path}</tt> could not be found.</p>"
|
29
|
+
# end
|
30
|
+
#end
|
31
|
+
|
32
|
+
|
33
|
+
def find_by_path(path)
|
34
|
+
begin
|
35
|
+
# page = Page.find_by_path(path)
|
36
|
+
Page.send(Comatose.config.page_finder, path)
|
37
|
+
Comatose::PageWrapper.new(page, self[:locals])
|
38
|
+
rescue
|
39
|
+
"<p>Page at <tt>#{path}</tt> could not be found.</p>"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def [](key)
|
45
|
+
#Comatose.logger.debug "[] called with key: #{key}"
|
46
|
+
#Comatose.logger.debug "current_user: #{current_user.to_s}"
|
47
|
+
case
|
48
|
+
when key.to_s.downcase == 'page'
|
49
|
+
@page
|
50
|
+
when key.to_s.downcase == 'current_user'
|
51
|
+
@current_user
|
52
|
+
when locals.has_key?(key)
|
53
|
+
locals[key]
|
54
|
+
when Comatose.registered_drops.has_key?(key)
|
55
|
+
Comatose.registered_drops[key]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def has_key?(key)
|
61
|
+
@@supported_methods.include?(key) or locals.has_key?(key) or Comatose.registered_drops.has_key?(key)
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def to_liquid
|
66
|
+
self
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def get_binding
|
71
|
+
binding
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def inspect
|
76
|
+
h = self.dup.merge(:page => page, :current_user => current_user, :locals => locals)
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def method_missing(method_id, *args)
|
81
|
+
#Comatose.logger.debug("processing_context: method_missing: method: #{method_id}")
|
82
|
+
#Comatose.logger.debug("processing_context: method_missing: args: #{args}")
|
83
|
+
method_name = method_id.to_s
|
84
|
+
case
|
85
|
+
when locals.has_key?(method_name)
|
86
|
+
locals[method_name]
|
87
|
+
when page.respond_to?(method_name)
|
88
|
+
page.send(method_name, args)
|
89
|
+
when Comatose.registered_drops.has_key?(method_name)
|
90
|
+
Comatose.registered_drops[method_name].context = self
|
91
|
+
Comatose.registered_drops[method_name].send(args)
|
92
|
+
#else Hash.respond_to?(method_id)
|
93
|
+
# super(method_id, args)
|
94
|
+
#else
|
95
|
+
# "ProcessingContext: Couldn't find #{method_id}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'action_dispatch/routing/mapper'
|
2
|
+
|
3
|
+
module Comatose
|
4
|
+
module Routes
|
5
|
+
|
6
|
+
def routes_for_comatose(opts={}, &block)
|
7
|
+
Comatose.logger.debug("routes_for_comatose options: #{opts}")
|
8
|
+
case
|
9
|
+
when opts.empty?
|
10
|
+
scope :module => "comatose" do
|
11
|
+
constraints(LocaleConstraint) do
|
12
|
+
match '/:locale/:page', :to => 'base#show'
|
13
|
+
match '/:locale', :to => 'base#show', :as => 'comatose_root'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
when opts[:mount]
|
17
|
+
scope :module => "comatose" do
|
18
|
+
constraints(LocaleConstraint) do
|
19
|
+
match "/:locale/#{opts[:mount]}/:page", :to => 'base#show', :index => opts[:mount]
|
20
|
+
match "/:locale/#{opts[:mount]}", :to => 'base#show', :index => opts[:mount], :as => "#{opts[:mount].underscore}_comatose_root"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
Comatose.add_mount_point(opts[:mount], { :index => opts[:index] || '' })
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def admin_routes_for_comatose(opts={}, &block)
|
29
|
+
Comatose.logger.debug("routes_for_comatose options: #{opts}")
|
30
|
+
case
|
31
|
+
when opts.empty?
|
32
|
+
namespace(:comatose, :path => "/:locale/comatose") do
|
33
|
+
constraints(LocaleConstraint) do
|
34
|
+
match '', :to => 'admin#index'
|
35
|
+
resources :pages, :controller => 'admin' do
|
36
|
+
collection do
|
37
|
+
post :import
|
38
|
+
get :export, :expire
|
39
|
+
end
|
40
|
+
|
41
|
+
member do
|
42
|
+
get :preview, :versions, :reorder
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
when opts[:mount]
|
48
|
+
namespace(:comatose, :path => "/:locale/comatose") do
|
49
|
+
# defaults :index => opts[:mount] do
|
50
|
+
constraints(LocaleConstraint) do
|
51
|
+
match '', :to => 'admin#index'
|
52
|
+
resources :pages, :controller => 'admin' do
|
53
|
+
collection do
|
54
|
+
post :import
|
55
|
+
get :export, :expire
|
56
|
+
end
|
57
|
+
|
58
|
+
member do
|
59
|
+
get :preview, :versions, :reorder
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
#end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
namespace :comatose do
|
2
|
+
#
|
3
|
+
# Customization Tasks
|
4
|
+
#
|
5
|
+
namespace :admin do
|
6
|
+
|
7
|
+
desc "Create Comatose views, layouts, and public files..."
|
8
|
+
task :customize do
|
9
|
+
puts "Copying public files..."
|
10
|
+
plugin_dir = File.join(File.dirname(__FILE__), '../../..')
|
11
|
+
FileUtils.cp(
|
12
|
+
Dir[File.join(plugin_dir, 'resources', 'public', 'stylesheets', '*.css')],
|
13
|
+
File.join(RAILS_ROOT, 'public', 'stylesheets'),
|
14
|
+
:verbose => true
|
15
|
+
)
|
16
|
+
FileUtils.cp(
|
17
|
+
Dir[File.join(plugin_dir, 'resources', 'public', 'javascripts', '*.js')],
|
18
|
+
File.join(RAILS_ROOT, 'public', 'javascripts'),
|
19
|
+
:verbose => true
|
20
|
+
)
|
21
|
+
puts "Copying application views..."
|
22
|
+
FileUtils.mkdir_p(File.join(RAILS_ROOT, 'app', 'views', 'comatose_admin'))
|
23
|
+
FileUtils.cp(
|
24
|
+
Dir[File.join(plugin_dir, 'views', 'comatose_admin', '*.html.erb')],
|
25
|
+
File.join(RAILS_ROOT, 'app', 'views', 'comatose_admin'),
|
26
|
+
:verbose => true
|
27
|
+
)
|
28
|
+
puts "Copying application layout..."
|
29
|
+
FileUtils.cp(
|
30
|
+
File.join(plugin_dir, 'views', 'layouts', 'comatose_admin_customize.html.erb'),
|
31
|
+
File.join(RAILS_ROOT, 'app', 'views', 'layouts', 'comatose_admin.html.erb'),
|
32
|
+
:verbose => true
|
33
|
+
)
|
34
|
+
puts "Finished."
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
desc "Removes the customized files... It doesn't ask for any confirmation, nor is it Subversion-safe -- so be warned!"
|
39
|
+
task :teardown do
|
40
|
+
puts "Removing public files..."
|
41
|
+
FileUtils.rm(
|
42
|
+
File.join(RAILS_ROOT, 'public', 'stylesheets', 'admin.css')
|
43
|
+
)
|
44
|
+
FileUtils.rm(
|
45
|
+
File.join(RAILS_ROOT, 'public', 'javascripts', 'admin.js')
|
46
|
+
)
|
47
|
+
|
48
|
+
puts "Removing application views..."
|
49
|
+
FileUtils.rm_rf(
|
50
|
+
File.join(RAILS_ROOT, 'app', 'views', 'comatose_admin')
|
51
|
+
)
|
52
|
+
FileUtils.rm(
|
53
|
+
File.join(RAILS_ROOT, 'app', 'views', 'layouts', 'comatose_admin.html.erb')
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
namespace :comatose do
|
2
|
+
#
|
3
|
+
# Data Migration Tasks
|
4
|
+
#
|
5
|
+
namespace :data do
|
6
|
+
|
7
|
+
def page_to_hash(page)
|
8
|
+
data = page.attributes.clone
|
9
|
+
# Pull out the specific, or unnecessary fields
|
10
|
+
%w(id parent_id updated_at author position version created_at full_path).each {|key| data.delete(key)}
|
11
|
+
if !page.children.empty?
|
12
|
+
data['children'] = []
|
13
|
+
page.children.each do |child|
|
14
|
+
data['children'] << page_to_hash(child)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
data
|
18
|
+
end
|
19
|
+
|
20
|
+
def hash_to_page_tree(hsh, page)
|
21
|
+
child_ary = hsh.delete 'children'
|
22
|
+
page.update_attributes(hsh)
|
23
|
+
page.save
|
24
|
+
child_ary.each do |child_hsh|
|
25
|
+
if child_pg = page.children.find_by_slug( child_hsh['slug'] )
|
26
|
+
hash_to_page_tree( child_hsh, child_pg )
|
27
|
+
else
|
28
|
+
hash_to_page_tree( child_hsh, page.children.create )
|
29
|
+
end
|
30
|
+
end if child_ary
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Saves a page tree from page FROM or '' to file TO_FILE or db/comatose-pages.yml"
|
34
|
+
task :export do
|
35
|
+
require "#{Rails.root}/config/environment"
|
36
|
+
|
37
|
+
root = ENV['FROM'] || ''
|
38
|
+
target = ENV['TO_FILE'] || 'db/comatose-pages.yml'
|
39
|
+
# Nested hash of the page tree...
|
40
|
+
from = Comatose::Page.find_by_path(root)
|
41
|
+
if from
|
42
|
+
data = page_to_hash( from )
|
43
|
+
File.open(target, 'w') {|f| f.write data.to_yaml }
|
44
|
+
else
|
45
|
+
puts "Could not find the page at '#{root}', export aborted!"
|
46
|
+
end
|
47
|
+
|
48
|
+
puts "Finished."
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Loads page tree data FROM_FILE or db/comatose-pages.yml in to TO or Comatose::Page.root"
|
52
|
+
task :import do
|
53
|
+
require "#{Rails.root}/config/environment"
|
54
|
+
|
55
|
+
src = ENV['FROM_FILE'] || 'db/comatose-pages.yml'
|
56
|
+
root = ENV['TO'] || ''
|
57
|
+
target = (root == '') ? Comatose::Page.root : Comatose::Page.find_by_path(root)
|
58
|
+
data = YAML::load( File.open(src) )
|
59
|
+
#hash_to_page(data, target)
|
60
|
+
if target
|
61
|
+
if root == ''
|
62
|
+
hash_to_page_tree(data, target)
|
63
|
+
else
|
64
|
+
if page = target.children.find_by_slug(data['slug'])
|
65
|
+
hash_to_page_tree(data, page)
|
66
|
+
else
|
67
|
+
hash_to_page_tree(data, target.children.create)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
else
|
71
|
+
puts "Could not find the page at '#{root}', import aborted!"
|
72
|
+
# TODO: Ask to create the specified path if it doesn't exist?
|
73
|
+
end
|
74
|
+
puts "Finished."
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
namespace :comatose do
|
2
|
+
#
|
3
|
+
# Setup Task...
|
4
|
+
#
|
5
|
+
namespace :setup do
|
6
|
+
|
7
|
+
desc "If the installation didn't add the images correctly, use this task"
|
8
|
+
task :copy_images do
|
9
|
+
sources = File.join(Comatose.gem_root, 'public/images/comatose', '*.gif')
|
10
|
+
destination_dir = File.join(Rails.root.to_s, 'public/images/comatose')
|
11
|
+
Comatose.logger.debug "[**Comatose**]: sources: #{sources}"
|
12
|
+
puts "[**Comatose**]: sources: #{sources}"
|
13
|
+
Comatose.logger.debug "[**Comatose**]: destination dir: #{destination_dir}"
|
14
|
+
puts "[**Comatose**]: destination dir: #{destination_dir}"
|
15
|
+
unless FileTest.exist? destination_dir
|
16
|
+
FileUtils.mkdir destination_dir
|
17
|
+
end
|
18
|
+
FileUtils.cp(Dir.glob(sources), destination_dir, :verbose => true)
|
19
|
+
puts "Finished."
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
desc "If the installation didn't add the stylesheets correctly, use this task"
|
24
|
+
task :copy_stylesheets do
|
25
|
+
sources = File.join(Comatose.gem_root, 'public/stylesheets/comatose', '*.css')
|
26
|
+
destination_dir = File.join(Rails.root.to_s, 'public/stylesheets/comatose')
|
27
|
+
Comatose.logger.debug "[**Comatose**]: sources: #{sources}"
|
28
|
+
puts "[**Comatose**]: sources: #{sources}"
|
29
|
+
Comatose.logger.debug "[**Comatose**]: destination dir: #{destination_dir}"
|
30
|
+
puts "[**Comatose**]: destination dir: #{destination_dir}"
|
31
|
+
unless FileTest.exist? destination_dir
|
32
|
+
FileUtils.mkdir destination_dir
|
33
|
+
end
|
34
|
+
FileUtils.cp(Dir.glob(sources), destination_dir, :verbose => true)
|
35
|
+
puts "Finished."
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
desc "If the installation didn't add the javascripts correctly, use this task"
|
40
|
+
task :copy_javascripts do
|
41
|
+
sources = File.join(Comatose.gem_root, 'public/javascripts/comatose', '*.js')
|
42
|
+
destination_dir = File.join(Rails.root.to_s, 'public/javascripts/comatose')
|
43
|
+
Comatose.logger.debug "[**Comatose**]: sources: #{sources}"
|
44
|
+
puts "[**Comatose**]: sources: #{sources}"
|
45
|
+
Comatose.logger.debug "[**Comatose**]: destination dir: #{destination_dir}"
|
46
|
+
puts "[**Comatose**]: destination dir: #{destination_dir}"
|
47
|
+
unless FileTest.exist? destination_dir
|
48
|
+
FileUtils.mkdir destination_dir
|
49
|
+
end
|
50
|
+
FileUtils.cp(Dir.glob(sources), destination_dir, :verbose => true)
|
51
|
+
|
52
|
+
sources = File.join(Comatose.gem_root, 'public/javascripts/jquery', '*')
|
53
|
+
destination_dir = File.join(Rails.root.to_s, 'public/javascripts/jquery')
|
54
|
+
Comatose.logger.debug "[**Comatose**]: sources: #{sources}"
|
55
|
+
puts "[**Comatose**]: sources: #{sources}"
|
56
|
+
Comatose.logger.debug "[**Comatose**]: destination dir: #{destination_dir}"
|
57
|
+
puts "[**Comatose**]: destination dir: #{destination_dir}"
|
58
|
+
unless FileTest.exist? destination_dir
|
59
|
+
FileUtils.mkdir destination_dir
|
60
|
+
end
|
61
|
+
FileUtils.cp(Dir.glob(sources), destination_dir, :verbose => true)
|
62
|
+
|
63
|
+
#source_tar = File.join(Comatose.gem_root, 'public/javascripts/wymeditor.tar')
|
64
|
+
#destination_dir = File.join(Rails.root.to_s, 'public/javascripts')
|
65
|
+
#Comatose.logger.debug "[**Comatose**]: source: #{source_tar}"
|
66
|
+
#puts "[**Comatose**]: source: #{source_tar}"
|
67
|
+
#Comatose.logger.debug "[**Comatose**]: destination dir: #{destination_dir}"
|
68
|
+
#puts "[**Comatose**]: destination dir: #{destination_dir}"
|
69
|
+
#unless FileTest.exist? destination_dir
|
70
|
+
# FileUtils.mkdir destination_dir
|
71
|
+
#end
|
72
|
+
#FileUtils.cp(source_tar, destination_dir, :verbose => true)
|
73
|
+
#`tar xvf #{File.join(destination_dir, "wymeditor.tar")}`
|
74
|
+
|
75
|
+
sources = File.join(Comatose.gem_root, 'public/javascripts', '*.js')
|
76
|
+
destination_dir = File.join(Rails.root.to_s, 'public/javascripts')
|
77
|
+
Comatose.logger.debug "[**Comatose**]: sources: #{sources}"
|
78
|
+
puts "[**Comatose**]: sources: #{sources}"
|
79
|
+
Comatose.logger.debug "[**Comatose**]: destination dir: #{destination_dir}"
|
80
|
+
puts "[**Comatose**]: destination dir: #{destination_dir}"
|
81
|
+
unless FileTest.exist? destination_dir
|
82
|
+
FileUtils.mkdir destination_dir
|
83
|
+
end
|
84
|
+
FileUtils.cp(Dir.glob(sources), destination_dir, :verbose => true)
|
85
|
+
|
86
|
+
|
87
|
+
puts "Finished."
|
88
|
+
end
|
89
|
+
|
90
|
+
# For use when upgrading...
|
91
|
+
|
92
|
+
def move(args)
|
93
|
+
if ENV['USE_SVN'] == 'true'
|
94
|
+
`svn move #{args}`
|
95
|
+
else
|
96
|
+
`mv #{args}`
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def delete(args)
|
101
|
+
if ENV['USE_SVN'] == 'true'
|
102
|
+
`svn delete #{args}`
|
103
|
+
else
|
104
|
+
`rm -rf #{args}`
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# TODO: Test the setup:restructure_customization task...
|
109
|
+
desc "[EXPERIMENTAL] Restructures customized admin folder to version 0.6 from older version -- Only run this if you have customized the admin. USE_SVN=true if you want to update subversion"
|
110
|
+
task :restructure_customization do
|
111
|
+
ENV['USE_SVN'] ||= 'false'
|
112
|
+
move 'public/javscripts/comatose.js public/javscripts/admin.js'
|
113
|
+
move 'public/stylesheets/comatose.css public/stylesheets/admin.css'
|
114
|
+
move 'app/views/comatose app/views/comatose_admin'
|
115
|
+
delete 'app/views/layouts/base.html.erb'
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|