aslakjo-comatose 2.0.5.2

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 (93) hide show
  1. data/CHANGELOG +195 -0
  2. data/INSTALL +20 -0
  3. data/LICENSE +20 -0
  4. data/MANIFEST +91 -0
  5. data/README.markdown +159 -0
  6. data/Rakefile +176 -0
  7. data/SPECS +61 -0
  8. data/about.yml +7 -0
  9. data/bin/comatose +112 -0
  10. data/comatose.gemspec +113 -0
  11. data/generators/comatose_migration/USAGE +15 -0
  12. data/generators/comatose_migration/comatose_migration_generator.rb +74 -0
  13. data/generators/comatose_migration/templates/migration.rb +35 -0
  14. data/generators/comatose_migration/templates/v4_upgrade.rb +15 -0
  15. data/generators/comatose_migration/templates/v6_upgrade.rb +23 -0
  16. data/generators/comatose_migration/templates/v7_upgrade.rb +22 -0
  17. data/init.rb +2 -0
  18. data/install.rb +18 -0
  19. data/lib/acts_as_versioned.rb +543 -0
  20. data/lib/comatose/comatose_drop.rb +79 -0
  21. data/lib/comatose/configuration.rb +69 -0
  22. data/lib/comatose/page_wrapper.rb +119 -0
  23. data/lib/comatose/processing_context.rb +69 -0
  24. data/lib/comatose/tasks/admin.rb +60 -0
  25. data/lib/comatose/tasks/data.rb +82 -0
  26. data/lib/comatose/tasks/setup.rb +52 -0
  27. data/lib/comatose/version.rb +4 -0
  28. data/lib/comatose.rb +33 -0
  29. data/lib/comatose_admin_controller.rb +395 -0
  30. data/lib/comatose_admin_helper.rb +37 -0
  31. data/lib/comatose_controller.rb +138 -0
  32. data/lib/comatose_helper.rb +3 -0
  33. data/lib/comatose_page.rb +141 -0
  34. data/lib/liquid/block.rb +96 -0
  35. data/lib/liquid/context.rb +190 -0
  36. data/lib/liquid/document.rb +17 -0
  37. data/lib/liquid/drop.rb +48 -0
  38. data/lib/liquid/errors.rb +7 -0
  39. data/lib/liquid/extensions.rb +53 -0
  40. data/lib/liquid/file_system.rb +62 -0
  41. data/lib/liquid/htmltags.rb +64 -0
  42. data/lib/liquid/standardfilters.rb +111 -0
  43. data/lib/liquid/standardtags.rb +399 -0
  44. data/lib/liquid/strainer.rb +42 -0
  45. data/lib/liquid/tag.rb +25 -0
  46. data/lib/liquid/template.rb +88 -0
  47. data/lib/liquid/variable.rb +39 -0
  48. data/lib/liquid.rb +52 -0
  49. data/lib/redcloth.rb +1129 -0
  50. data/lib/support/class_options.rb +36 -0
  51. data/lib/support/inline_rendering.rb +48 -0
  52. data/lib/support/route_mapper.rb +50 -0
  53. data/lib/text_filters/markdown.rb +14 -0
  54. data/lib/text_filters/markdown_smartypants.rb +15 -0
  55. data/lib/text_filters/none.rb +8 -0
  56. data/lib/text_filters/rdoc.rb +13 -0
  57. data/lib/text_filters/simple.rb +8 -0
  58. data/lib/text_filters/textile.rb +15 -0
  59. data/lib/text_filters.rb +140 -0
  60. data/rails/init.rb +3 -0
  61. data/resources/layouts/comatose_admin_template.html.erb +28 -0
  62. data/resources/public/images/collapsed.gif +0 -0
  63. data/resources/public/images/expanded.gif +0 -0
  64. data/resources/public/images/no-children.gif +0 -0
  65. data/resources/public/images/page.gif +0 -0
  66. data/resources/public/images/spinner.gif +0 -0
  67. data/resources/public/images/title-hover-bg.gif +0 -0
  68. data/resources/public/javascripts/comatose_admin.js +401 -0
  69. data/resources/public/stylesheets/comatose_admin.css +404 -0
  70. data/tasks/comatose.rake +9 -0
  71. data/test/behaviors.rb +106 -0
  72. data/test/fixtures/comatose_pages.yml +96 -0
  73. data/test/functional/comatose_admin_controller_test.rb +114 -0
  74. data/test/functional/comatose_controller_test.rb +44 -0
  75. data/test/javascripts/test.html +26 -0
  76. data/test/javascripts/test_runner.js +307 -0
  77. data/test/test_helper.rb +55 -0
  78. data/test/unit/class_options_test.rb +52 -0
  79. data/test/unit/comatose_page_test.rb +136 -0
  80. data/test/unit/processing_context_test.rb +108 -0
  81. data/test/unit/text_filters_test.rb +52 -0
  82. data/views/comatose_admin/_form.html.erb +96 -0
  83. data/views/comatose_admin/_page_list_item.html.erb +60 -0
  84. data/views/comatose_admin/delete.html.erb +18 -0
  85. data/views/comatose_admin/edit.html.erb +5 -0
  86. data/views/comatose_admin/index.html.erb +29 -0
  87. data/views/comatose_admin/new.html.erb +5 -0
  88. data/views/comatose_admin/reorder.html.erb +30 -0
  89. data/views/comatose_admin/versions.html.erb +40 -0
  90. data/views/layouts/comatose_admin.html.erb +837 -0
  91. data/views/layouts/comatose_admin_customize.html.erb +28 -0
  92. data/views/layouts/comatose_content.html.erb +17 -0
  93. metadata +148 -0
@@ -0,0 +1,36 @@
1
+ class Class
2
+ def define_option(name, default=nil)
3
+ sym = name.to_sym
4
+ cattr_reader(sym)
5
+ cattr_writer(sym)
6
+ send("#{name.to_s}=", default)
7
+ end
8
+
9
+ def blockable_attr_accessor(sym)
10
+ module_eval(<<-EVAL, __FILE__, __LINE__)
11
+ def #{sym}(&block)
12
+ if block_given?
13
+ @#{sym} = block
14
+ else
15
+ @#{sym}
16
+ end
17
+ end
18
+ def #{sym}=(value)
19
+ @#{sym} = value
20
+ end
21
+ EVAL
22
+ end
23
+ end
24
+
25
+ class Module
26
+ def attr_accessor_with_default(sym, default = nil, &block)
27
+ raise 'Default value or block required' unless !default.nil? || block
28
+ define_method(sym, block_given? ? block : Proc.new { default })
29
+ module_eval(<<-EVAL, __FILE__, __LINE__)
30
+ def #{sym}=(value)
31
+ class << self; attr_reader :#{sym} end
32
+ @#{sym} = value
33
+ end
34
+ EVAL
35
+ end
36
+ end
@@ -0,0 +1,48 @@
1
+ # Extends the view to support rendering inline comatose pages...
2
+ ActionView::Base.class_eval do
3
+ alias_method :render_otherwise, :render
4
+
5
+ def render(options = {}, old_local_assigns = {}, &block) #:nodoc:
6
+ if options.is_a?(Hash) && page_name = options.delete(:comatose)
7
+ render_comatose(page_name, options[:params] || options)
8
+ else
9
+ render_otherwise(options, old_local_assigns, &block)
10
+ end
11
+ end
12
+
13
+ def render_comatose(page_path, params = {})
14
+ params = {
15
+ :silent => false,
16
+ :use_cache => true,
17
+ :locals => {}
18
+ }.merge(params)
19
+ if params[:use_cache] and params[:locals].empty?
20
+ render_cached_comatose_page(page_path, params)
21
+ else
22
+ render_comatose_page(page_path, params)
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ def render_cached_comatose_page(page_path, params)
29
+ key = page_path.gsub(/\//, '+')
30
+ unless html = controller.read_fragment(key)
31
+ html = render_comatose_page( page_path, params )
32
+ controller.write_fragment(key, html) unless Comatose.config.disable_caching
33
+ end
34
+ html
35
+ end
36
+
37
+ def render_comatose_page(page_path, params)
38
+ if page = ComatosePage.find_by_path(page_path)
39
+ # Add the request params to the context...
40
+ params[:locals]['params'] = controller.params
41
+ html = page.to_html( params[:locals] )
42
+ else
43
+ html = params[:silent] ? '' : "<p><tt>#{page_path}</tt> not found</p>"
44
+ end
45
+ end
46
+
47
+ end
48
+
@@ -0,0 +1,50 @@
1
+ # For use with 'Edge Rails'
2
+ class ActionController::Routing::RouteSet::Mapper
3
+
4
+ # For mounting a page to a path
5
+ def comatose_root( path, options={} )
6
+ opts = {
7
+ :index => '',
8
+ :layout => 'comatose_content.html.erb',
9
+ :use_cache => 'true',
10
+ :cache_path => nil,
11
+ :named_route=> nil
12
+ }.merge(options)
13
+ # Ensure the controller is aware of the mount point...
14
+ Comatose.add_mount_point(path, opts)
15
+ # Add the route...
16
+ opts[:controller] = 'comatose'
17
+ opts[:action] ='show'
18
+ route_name = opts.delete(:named_route)
19
+ unless route_name.nil?
20
+ named_route( route_name, "#{path}/*page", opts )
21
+ else
22
+ if opts[:index] == '' # if it maps to the root site URI, name it comatose_root
23
+ named_route( 'comatose_root', "#{path}/*page", opts )
24
+ else
25
+ connect( "#{path}/*page", opts )
26
+ end
27
+ end
28
+ end
29
+
30
+ # For mounting the admin
31
+ def comatose_admin( path='comatose_admin', options={} )
32
+ opts = {
33
+ :controller => 'comatose_admin',
34
+ :named_route => 'comatose_admin'
35
+ }.merge(options)
36
+ route_name = opts.delete(:named_route)
37
+ named_route( route_name, "#{path}/:action/:id", opts )
38
+ end
39
+
40
+ def method_missing( name, *args, &proc )
41
+ if name.to_s.starts_with?( 'comatose_' )
42
+ opts = (args.last.is_a?(Hash)) ? args.pop : {}
43
+ opts[:named_route] = name.to_s #[9..-1]
44
+ comatose_root( *(args << opts) )
45
+ else
46
+ super unless args.length >= 1 && proc.nil?
47
+ @set.add_named_route(name, *args)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ #
2
+ # MARKDOWN
3
+ #
4
+ TextFilters.define :markdown, "Markdown" do
5
+ require 'bluecloth'
6
+
7
+ def render_text(text)
8
+ BlueCloth.new(text).to_html
9
+ end
10
+
11
+ def create_link(title, url)
12
+ "[#{title}](#{url})"
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ #
2
+ # MARKDOWN + SMARTYPANTS
3
+ #
4
+ TextFilters.define :markdown_smartypants, "Markdown + SmartyPants" do
5
+ require 'bluecloth'
6
+ require 'rubypants'
7
+
8
+ def render_text(text)
9
+ RubyPants.new( BlueCloth.new(text).to_html ).to_html
10
+ end
11
+
12
+ def create_link(title, url)
13
+ "[#{title}](#{url})"
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ #
2
+ # NONE
3
+ #
4
+ TextFilters.define :none, "[No Filter]" do
5
+ def render_text(text)
6
+ text
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ #
2
+ # RDOC
3
+ #
4
+ TextFilters.define :rdoc, "RDoc" do
5
+ require 'rdoc/markup/simple_markup'
6
+ require 'rdoc/markup/simple_markup/to_html'
7
+
8
+ def render_text(text)
9
+ p = SM::SimpleMarkup.new
10
+ h = SM::ToHtml.new
11
+ p.convert(text, h)
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ #
2
+ # SIMPLE
3
+ #
4
+ TextFilters.define :simple, "Simple" do
5
+ def render_text(text)
6
+ text.gsub("\n", '<br/>')
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ #
2
+ # TEXTILE
3
+ #
4
+ TextFilters.define :textile, "Textile" do
5
+ require 'redcloth'
6
+
7
+ def render_text(text)
8
+ RedCloth.new(text).to_html(:refs_markdown, :textile, :markdown)
9
+ end
10
+
11
+ def create_link(title, url)
12
+ %Q|"#{title}":#{url}|
13
+ end
14
+
15
+ end
@@ -0,0 +1,140 @@
1
+ require 'support/class_options'
2
+
3
+ class TextFilters
4
+
5
+ define_option :default_processor, :liquid
6
+ define_option :default_filter, "Textile"
7
+ define_option :logger, nil
8
+
9
+ @registered_filters = {}
10
+ @registered_titles = {}
11
+
12
+ attr_reader :name
13
+ attr_reader :title
14
+ def initialize(name, title)
15
+ @name = name
16
+ @title = title
17
+ end
18
+
19
+ # The default create_link method...
20
+ # Override for your specific filter, if needed, in the #define block
21
+ def create_link(title, url)
22
+ %Q|<a href="#{url}">#{title}</a>|
23
+ end
24
+
25
+ # Process the text with using the specified context
26
+ def process_text(text, context, processor=nil)
27
+ case (processor || TextFilters.default_processor)
28
+ when :erb then process_with_erb(text, context)
29
+ when :liquid then process_with_liquid(text, context)
30
+ else raise "Unknown Text Processor '#{processor.to_s}'"
31
+ end
32
+ end
33
+
34
+ class << self
35
+ private :new
36
+ attr_reader :registered_filters
37
+ attr_reader :registered_titles
38
+
39
+ # Use this to create and register your TextFilters
40
+ def define(name, title, &block)
41
+ begin
42
+ p = new(name, title)
43
+ p.instance_eval(&block)
44
+ if p.respond_to? :render_text
45
+ registered_titles[title] = name
46
+ registered_filters[name] = p
47
+ else
48
+ raise "#render_text isn't implemented in this class"
49
+ end
50
+ rescue LoadError
51
+ TextFilters.logger.debug "Filter '#{name}' was not included: #{$!}" unless TextFilters.logger.nil?
52
+ rescue
53
+ TextFilters.logger.debug "Filter '#{name}' was not included: #{$!}" unless TextFilters.logger.nil?
54
+ end
55
+ end
56
+
57
+ def get_filter(name)
58
+ name = TextFilters.default_filter if name.nil?
59
+ name = registered_titles[name] if name.is_a? String
60
+ filter = registered_filters[name]
61
+ raise "No filter found for '#{name}' in registered_titles: #{registered_titles.inspect} or registered_filters: #{registered_filters.inspect}" unless filter
62
+ filter
63
+ end
64
+
65
+ def [](name)
66
+ get_filter(name)
67
+ end
68
+
69
+ def all
70
+ registered_filters
71
+ end
72
+
73
+ def all_titles
74
+ registered_titles.keys
75
+ end
76
+
77
+ def render_text(text, name=nil)
78
+ get_filter(name).render_text(text)
79
+ end
80
+
81
+ def process_text(text, context=nil, name=nil, processor=nil)
82
+ get_filter(name).process_text(text, context, processor)
83
+ end
84
+
85
+ # Call
86
+ def transform(text, context=nil, name=nil, processor=nil)
87
+ render_text( process_text(text, context, name, processor), name )
88
+ end
89
+ end
90
+
91
+ private
92
+
93
+ # This is an instance method so that it won't puke on requiring
94
+ # a non-existant library until it's being registered -- the only
95
+ # place I can really capture the LoadError
96
+ def require(name)
97
+ Kernel.require name
98
+ end
99
+
100
+ # Use ERB to process text...
101
+ def process_with_erb(text, context)
102
+ begin
103
+ ERB.new( text ).result( context.get_binding )
104
+ rescue
105
+ raise "ERB Error: #{$!}"
106
+ end
107
+ end
108
+
109
+ # Use Liquid to process text...
110
+ def process_with_liquid(text, context={})
111
+ begin
112
+ context = context.stringify_keys if context.respond_to? :stringify_keys
113
+ Liquid::Template.parse(text).render(context)
114
+ rescue
115
+ raise "Liquid Error: #{$!}"
116
+ end
117
+ end
118
+
119
+ end
120
+
121
+ class Hash
122
+ # Having the method_missing catchall in conjunction with get_binding
123
+ # allows us to use the hash as a Context for ERB
124
+ def method_missing(meth, *arg)
125
+ if self.has_key? meth.to_s
126
+ self[meth.to_s]
127
+ else
128
+ super
129
+ end
130
+ end
131
+ # Gets the binding object for use with ERB
132
+ def get_binding
133
+ binding
134
+ end
135
+ end
136
+
137
+
138
+ Dir[File.join(File.dirname(__FILE__), 'text_filters', '*.rb')].each do |path|
139
+ require "text_filters/#{File.basename(path)}"
140
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Init for gem version of Comatose
2
+
3
+ require 'comatose'
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html class="noscript" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=<%%= Comatose.config.content_type %>"/>
6
+ <title>Comatose Admin</title>
7
+ <%= style_contents %>
8
+ <%%= javascript_include_tag :defaults %>
9
+ <%= script_contents %>
10
+ </head>
11
+ <body>
12
+ <div id="page-container">
13
+ <div id="header">
14
+ <h1><%%= link_to Comatose.config.admin_title, :controller=>controller.controller_name, :action=>'index' %></h1>
15
+ <div id="flash">
16
+ <span id="flash-content"><%%= flash[:notice] %></span>
17
+ </div>
18
+ <h5><%%= Comatose.config.admin_sub_title %></h5>
19
+ </div>
20
+ <div id="content">
21
+ <%%= yield %>
22
+ </div>
23
+ <div id="footer">
24
+ Powered by <a href="http://comatose.rubyforge.org" target="_new_window">Comatose <%%= Comatose::VERSION_STRING %></a>, created by <a href="http://www.mattmccray.com" target="_new_window">M@ McCray</a>.
25
+ </div>
26
+ </div>
27
+ </body>
28
+ </html>
Binary file
Binary file