public
Fork of defunkt/acts_as_textiled
Description: Makes your models act as textiled.
Homepage: http://errtheblog.com/posts/12-actsastextiled
Clone URL: git://github.com/github/acts_as_textiled.git
add in acts_as_textiled api changes
defunkt (author)
Sun Jun 03 04:35:21 -0700 2007
commit  eac71a20b391ee28623664658aaf17b26c4ce0cf
tree    2f2d61f415e787bdf1b81deafae1f5539462c2cf
parent  d5fd7eebebede89cb9ffc152d6e08d2364df9bc0
...
 
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
8
0
@@ -1,3 +1,8 @@
0
+= 0.3
0
+ - Fixed Model.textiled = false bug
0
+ - Refactored tests
0
+ - Changed api from @story.description_plain to @story.description(:plain) - kept old way, though
0
+
0
 = 0.2
0
 
0
   * Fix issue with object.attribute_plain overwriting the original attribute [Thanks, James]
0
...
21
22
23
24
 
25
26
27
 
28
29
30
...
90
91
92
93
 
94
95
96
...
21
22
23
 
24
25
26
 
27
28
29
30
...
90
91
92
 
93
94
95
96
0
@@ -21,10 +21,10 @@ You need RedCloth, of course. And Rails.
0
   >> story.description
0
   => "<p>This is <strong>cool</strong>.</p>"
0
 
0
- >> story.description_source
0
+ >> story.description(:source)
0
   => "This is *cool*."
0
 
0
- >> story.description_plain
0
+ >> story.description(:plain)
0
   => "This is cool."
0
 
0
   >> story.description = "I _know_!"
0
@@ -90,7 +90,7 @@ You'll see the Textile plaintext in the text field. It Just Works.
0
 If you're being a bit unconvential, no worries. You can still get at your
0
 raw Textile like so:
0
 
0
- Description: <br/> <%= text_field_tag :description, @story.description_source %>
0
+ Description: <br/> <%= text_field_tag :description, @story.description(:source) %>
0
 
0
 And there's always object.textiled = false, as demo'd above.
0
 
...
3
4
5
6
 
7
...
3
4
5
 
6
7
0
@@ -3,5 +3,5 @@ summary:
0
 homepage: http://errtheblog.com/post/14
0
 plugin: http://require.errtheblog.com/svn/acts_as_textiled
0
 license: MIT
0
-version: 0.1
0
+version: 0.3
0
 rails_version: 1.1+
...
 
1
2
...
1
2
3
0
@@ -1,2 +1,3 @@
0
+require 'RedCloth'
0
 require 'acts_as_textiled'
0
 ActiveRecord::Base.send(:include, Err::Acts::Textiled)
...
6
7
8
9
 
10
11
12
 
13
14
15
 
 
16
17
18
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
21
22
23
 
 
 
 
 
24
25
26
...
6
7
8
 
9
10
11
 
12
13
 
 
14
15
16
 
 
 
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
 
 
33
34
35
36
37
38
39
40
0
@@ -6,21 +6,35 @@ module Err
0
       end
0
 
0
       module ClassMethods
0
- def acts_as_textiled(*attrs)
0
+ def acts_as_textiled(*attributes)
0
           @textiled_attributes = []
0
 
0
- @textiled_unicode = "".respond_to? :chars
0
+ @textiled_unicode = String.new.respond_to? :chars
0
 
0
- ruled = Hash === attrs.last ? attrs.pop : {}
0
- attrs += ruled.keys
0
+ ruled = attributes.last.is_a?(Hash) ? attributes.pop : {}
0
+ attributes += ruled.keys
0
 
0
- attrs.each do |attr|
0
- define_method(attr) do
0
- textiled[attr.to_s] ||= RedCloth.new(self[attr], Array(ruled[attr])).to_html if self[attr]
0
+ type_options = %w( plain source )
0
+
0
+ attributes.each do |attribute|
0
+ define_method(attribute) do |*type|
0
+ type = type.first
0
+
0
+ if type.nil? && self[attribute]
0
+ textiled[attribute.to_s] ||= RedCloth.new(self[attribute], Array(ruled[attribute])).to_html
0
+ elsif type.nil? && self[attribute].nil?
0
+ nil
0
+ elsif type_options.include?(type.to_s)
0
+ send("#{attribute}_#{type}")
0
+ else
0
+ raise "I don't understand the `#{type}' option. Try #{type_options.join(' or ')}."
0
+ end
0
             end
0
- define_method("#{attr}_plain", proc { strip_redcloth_html(__send__(attr)) if __send__(attr) } )
0
- define_method("#{attr}_source", proc { __send__("#{attr}_before_type_cast") } )
0
- @textiled_attributes << attr
0
+
0
+ define_method("#{attribute}_plain", proc { strip_redcloth_html(__send__(attribute)) if __send__(attribute) } )
0
+ define_method("#{attribute}_source", proc { __send__("#{attribute}_before_type_cast") } )
0
+
0
+ @textiled_attributes << attribute
0
           end
0
 
0
           include Err::Acts::Textiled::InstanceMethods
...
17
18
19
20
21
 
 
22
23
24
25
26
27
28
29
 
 
30
31
32
33
34
 
 
 
 
 
 
35
36
37
...
17
18
19
 
 
20
21
22
23
24
25
26
27
 
 
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
0
@@ -17,21 +17,27 @@ context "An ActiveRecord instance acting as textiled" do
0
     desc_plain = '_why announces Sandbox'
0
 
0
     story.description.should.equal desc_html
0
- #story.description(:source).should.equal desc_textile
0
- #story.description(:plain).should.equal desc_plain
0
+ story.description(:source).should.equal desc_textile
0
+ story.description(:plain).should.equal desc_plain
0
 
0
     story.description_source.should.equal desc_textile
0
     story.description_plain.should.equal desc_plain
0
 
0
     # make sure we don't overwrite anything - thanks James
0
     story.description.should.equal desc_html
0
- #story.description(:source).should.equal desc_textile
0
- #story.description(:plain).should.equal desc_plain
0
+ story.description(:source).should.equal desc_textile
0
+ story.description(:plain).should.equal desc_plain
0
 
0
     story.description_source.should.equal desc_textile
0
     story.description_plain.should.equal desc_plain
0
   end
0
 
0
+ specify "should raise when given a non-sensical option" do
0
+ story = Story.find(1)
0
+
0
+ proc { story.description(:cassadaga) }.should.raise
0
+ end
0
+
0
   specify "should pick up changes to attributes" do
0
     story = Story.find(2)
0
     

Comments

    No one has commented yet.