merb_comatose 0.0.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.
@@ -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,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,138 @@
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
+ registered_filters[name]
61
+ end
62
+
63
+ def [](name)
64
+ get_filter(name)
65
+ end
66
+
67
+ def all
68
+ registered_filters
69
+ end
70
+
71
+ def all_titles
72
+ registered_titles.keys
73
+ end
74
+
75
+ def render_text(text, name=nil)
76
+ get_filter(name).render_text(text)
77
+ end
78
+
79
+ def process_text(text, context=nil, name=nil, processor=nil)
80
+ get_filter(name).process_text(text, context, processor)
81
+ end
82
+
83
+ # Call
84
+ def transform(text, context=nil, name=nil, processor=nil)
85
+ render_text( process_text(text, context, name, processor), name )
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ # This is an instance method so that it won't puke on requiring
92
+ # a non-existant library until it's being registered -- the only
93
+ # place I can really capture the LoadError
94
+ def require(name)
95
+ Kernel.require name
96
+ end
97
+
98
+ # Use ERB to process text...
99
+ def process_with_erb(text, context)
100
+ begin
101
+ ERB.new( text ).result( context.get_binding )
102
+ rescue
103
+ raise "ERB Error: #{$!}"
104
+ end
105
+ end
106
+
107
+ # Use Liquid to process text...
108
+ def process_with_liquid(text, context={})
109
+ begin
110
+ context = context.stringify_keys if context.respond_to? :stringify_keys
111
+ Liquid::Template.parse(text).render(context)
112
+ rescue
113
+ raise "Liquid Error: #{$!}"
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+ class Hash
120
+ # Having the method_missing catchall in conjunction with get_binding
121
+ # allows us to use the hash as a Context for ERB
122
+ def method_missing(meth, *arg)
123
+ if self.has_key? meth.to_s
124
+ self[meth.to_s]
125
+ else
126
+ super
127
+ end
128
+ end
129
+ # Gets the binding object for use with ERB
130
+ def get_binding
131
+ binding
132
+ end
133
+ end
134
+
135
+
136
+ Dir[File.join(File.dirname(__FILE__), 'text_filters', '*.rb')].each do |path|
137
+ require "text_filters/#{File.basename(path)}"
138
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "merb_comatose" do
4
+ it "should do nothing" do
5
+ true.should == true
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb_comatose
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jacques Crocker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-17 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Partial Port of Comatose with focus on rendering from Comatose Pages (no admin yet)
17
+ email: merbjedi@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - LICENSE
25
+ - TODO
26
+ files:
27
+ - LICENSE
28
+ - README
29
+ - Rakefile
30
+ - TODO
31
+ - lib/class_options.rb
32
+ - lib/comatose
33
+ - lib/comatose/comatose_drop.rb
34
+ - lib/comatose/configuration.rb
35
+ - lib/comatose/page_wrapper.rb
36
+ - lib/comatose/processing_context.rb
37
+ - lib/comatose/version.rb
38
+ - lib/liquid
39
+ - lib/liquid/block.rb
40
+ - lib/liquid/context.rb
41
+ - lib/liquid/document.rb
42
+ - lib/liquid/drop.rb
43
+ - lib/liquid/errors.rb
44
+ - lib/liquid/extensions.rb
45
+ - lib/liquid/file_system.rb
46
+ - lib/liquid/htmltags.rb
47
+ - lib/liquid/standardfilters.rb
48
+ - lib/liquid/standardtags.rb
49
+ - lib/liquid/strainer.rb
50
+ - lib/liquid/tag.rb
51
+ - lib/liquid/template.rb
52
+ - lib/liquid/variable.rb
53
+ - lib/liquid.rb
54
+ - lib/merb_comatose
55
+ - lib/merb_comatose/merbtasks.rb
56
+ - lib/merb_comatose.rb
57
+ - lib/redcloth.rb
58
+ - lib/support
59
+ - lib/support/class_options.rb
60
+ - lib/text_filters
61
+ - lib/text_filters/markdown.rb
62
+ - lib/text_filters/markdown_smartypants.rb
63
+ - lib/text_filters/none.rb
64
+ - lib/text_filters/rdoc.rb
65
+ - lib/text_filters/simple.rb
66
+ - lib/text_filters/textile.rb
67
+ - lib/text_filters.rb
68
+ - spec/merb_comatose_spec.rb
69
+ - spec/spec_helper.rb
70
+ has_rdoc: true
71
+ homepage: http://merbjedi.com/
72
+ post_install_message:
73
+ rdoc_options: []
74
+
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ requirements: []
90
+
91
+ rubyforge_project: merb
92
+ rubygems_version: 1.3.1
93
+ signing_key:
94
+ specification_version: 2
95
+ summary: Partial Port of Comatose with focus on rendering from Comatose Pages (no admin yet)
96
+ test_files: []
97
+