public
Description: Makes your models act as textiled.
Homepage: http://errtheblog.com/posts/12-actsastextiled
Clone URL: git://github.com/defunkt/acts_as_textiled.git
Search Repo:
initial import
defunkt (author)
Wed Aug 09 22:22:32 -0700 2006
commit  cdefbea1dee9c1240e1282b1c2fb6d4b7d20f55c
tree    c8519eaeac02e327b798054b3f325cf2601fc13d
...
 
 
 
...
1
2
3
0
@@ -0,0 +1,3 @@
0
+= 0.1
0
+
0
+ * Initial import
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
0
@@ -0,0 +1,18 @@
0
+Copyright (c) 2006 Chris Wanstrath
0
+
0
+Permission is hereby granted, free of charge, to any person obtaining a copy of
0
+this software and associated documentation files (the "Software"), to deal in
0
+the Software without restriction, including without limitation the rights to
0
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
0
+the Software, and to permit persons to whom the Software is furnished to do so,
0
+subject to the following conditions:
0
+
0
+The above copyright notice and this permission notice shall be included in all
0
+copies or substantial portions of the Software.
0
+
0
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
0
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
0
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
0
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0
\ No newline at end of file
0
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
0
@@ -0,0 +1,121 @@
0
+= Acts as Textiled
0
+
0
+This simple plugin allows you to forget about constantly rendering Textile in
0
+your application. Instead, you can rest easy knowing the Textile fields you
0
+want to display as HTML will always be displayed as HTML (unless you tell your
0
+code otherwise).
0
+
0
+No database modifications are needed.
0
+
0
+You need RedCloth, of course. And Rails.
0
+
0
+== Usage
0
+
0
+ class Story < ActiveRecord::Base
0
+ acts_as_textiled :body_text, :description
0
+ end
0
+
0
+ >> story = Story.find(3)
0
+ => #<Story:0x245fed8 ... >
0
+
0
+ >> story.description
0
+ => "<p>This is <strong>cool</strong>.</p>"
0
+
0
+ >> story.description_source
0
+ => "This is *cool*."
0
+
0
+ >> story.description_plain
0
+ => "This is cool."
0
+
0
+ >> story.description = "I _know_!"
0
+ => "I _know_!"
0
+
0
+ >> story.save
0
+ => true
0
+
0
+ >> story.description
0
+ => "<p>I <em>know</em>!</p>"
0
+
0
+ >> story.textiled = false
0
+ => false
0
+
0
+ >> story.description
0
+ => "I _know_!"
0
+
0
+ >> story.textiled = true
0
+ => true
0
+
0
+ >> story.description
0
+ => "<p>I <em>know</em>!</p>"
0
+
0
+=== Different Modes
0
+
0
+RedCloth supports different modes, such as :lite_mode. To use a mode on
0
+a specific attribute simply pass it in as an options hash after any
0
+attributes you don't want to mode-ify. Like so:
0
+
0
+ class Story < ActiveRecord::Base
0
+ acts_as_textiled :body_text, :description => :lite_mode
0
+ end
0
+
0
+Or:
0
+
0
+ class Story < ActiveRecord::Base
0
+ acts_as_textiled :body_text => :lite_mode, :description => :lite_mode
0
+ end
0
+
0
+You can also pass in multiple modes per attribute:
0
+
0
+ class Story < ActiveRecord::Base
0
+ acts_as_textiled :body_text, :description => [ :lite_mode, :no_span_caps ]
0
+ end
0
+
0
+Get it? Now let's say you have an admin tool and you want the text to be displayed
0
+in the text boxes / fields as plaintext. Do you have to change all your views?
0
+
0
+Hell no.
0
+
0
+=== form_for
0
+
0
+Are you using form_for? If you are, you don't have to change any code at all.
0
+
0
+ <% form_for :story, @story do |f| %>
0
+ Description: <br/> <%= f.text_field :description %>
0
+ <% end %>
0
+
0
+You'll see the Textile plaintext in the text field. It Just Works.
0
+
0
+=== form tags
0
+
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
+
0
+And there's always object.textiled = false, as demo'd above.
0
+
0
+== Pre-fetching
0
+
0
+acts_as_textiled locally caches rendered HTML once the attribute in question has
0
+been requested. Obviously this doesn't bode well for marshalling or caching.
0
+
0
+If you need to force your object to build and cache HTML for all textiled attributes,
0
+call the +textilize+ method on your object.
0
+
0
+If you're real crazy you can even do something like this:
0
+
0
+ class Story < ActiveRecord::Base
0
+ acts_as_textiled :body_text, :description
0
+
0
+ def after_find
0
+ textilize
0
+ end
0
+ end
0
+
0
+All your Textile will now be ready to go in spiffy HTML format. But you probably
0
+won't need to do this.
0
+
0
+Enjoy.
0
+
0
+>> Chris Wanstrath
0
+=> chris[at]ozmm[dot]org
...
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
0
@@ -0,0 +1,7 @@
0
+author: Chris Wanstrath (chris[at]ozmm[dot]org)
0
+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
+rails_version: 1.1+
...
 
 
...
1
2
0
@@ -0,0 +1,2 @@
0
+require 'acts_as_textiled'
0
+ActiveRecord::Base.send(:include, Err::Acts::Textiled)
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
0
@@ -0,0 +1,85 @@
0
+module Err
0
+ module Acts #:nodoc: all
0
+ module Textiled
0
+ def self.included(klass)
0
+ klass.extend ClassMethods
0
+ end
0
+
0
+ module ClassMethods
0
+ def acts_as_textiled(*attrs)
0
+ ruled = attrs.last.is_a?(Hash) ? attrs.pop : {}
0
+ attrs += ruled.keys
0
+
0
+ attrs.each do |attr|
0
+ define_method(attr) do
0
+ textiled[attr.to_s] ||= RedCloth.new(read_attribute(attr), Array(ruled[attr])).to_html
0
+ end
0
+ define_method("#{attr}_plain", proc { strip_redcloth_html(__send__(attr)) } )
0
+ define_method("#{attr}_source", proc { __send__("#{attr}_before_type_cast") } )
0
+ end
0
+
0
+ include Err::Acts::Textiled::InstanceMethods
0
+ end
0
+ end
0
+
0
+ module InstanceMethods
0
+ def textiled
0
+ textiled? ? (@textiled ||= {}) : @attributes.dup
0
+ end
0
+
0
+ def textiled?
0
+ @is_textiled.nil? ? true : @is_textiled
0
+ end
0
+
0
+ def textiled=(bool)
0
+ @is_textiled = !!bool
0
+ end
0
+
0
+ def textilize
0
+ logger.debug "I GOT HIT!"
0
+ attribute_names.each { |attr| __send__(attr) }
0
+ end
0
+
0
+ def reload
0
+ textiled.clear
0
+ super
0
+ end
0
+
0
+ def write_attribute(attr_name, value)
0
+ textiled[attr_name.to_s] = nil
0
+ super(attr_name, value)
0
+ end
0
+
0
+ private
0
+ def strip_redcloth_html(html)
0
+ html.gsub!(html_regexp, '')
0
+ redcloth_glyphs.each do |(entity, char)|
0
+ html.gsub!(entity, char)
0
+ end
0
+ html
0
+ end
0
+
0
+ def redcloth_glyphs
0
+ [[ '&#8217;', "'" ],
0
+ [ '&#8216;', "'" ],
0
+ [ '&lt;', '<' ],
0
+ [ '&gt;', '>' ],
0
+ [ '&#8221;', '"' ],
0
+ [ '&#8220;', '"' ],
0
+ [ '&#8230;', '...' ],
0
+ [ '\1&#8212;', '--' ],
0
+ [ ' &rarr; ', '->' ],
0
+ [ ' &#8211; ', '-' ],
0
+ [ '&#215;', 'x' ],
0
+ [ '&#8482;', '(TM)' ],
0
+ [ '&#174;', '(R)' ],
0
+ [ '&#169;', '(C)' ]]
0
+ end
0
+
0
+ def html_regexp
0
+ %r{<(?:[^>"']+|"(?:\\.|[^\\"]+)*"|'(?:\\.|[^\\']+)*')*>}xm
0
+ end
0
+ end
0
+ end
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
0
@@ -0,0 +1,18 @@
0
+sqlite:
0
+ :adapter: sqlite
0
+ :dbfile: ':memory:'
0
+sqlite3:
0
+ :adapter: sqlite3
0
+ :dbfile: ':memory:'
0
+postgresql:
0
+ :adapter: postgresql
0
+ :username: postgres
0
+ :password: postgres
0
+ :database: acts_as_textiled_plugin_test
0
+ :min_messages: ERROR
0
+mysql:
0
+ :adapter: mysql
0
+ :host: localhost
0
+ :username: root
0
+ :password:
0
+ :database: acts_as_textiled_plugin_test
...
 
 
 
 
...
1
2
3
4
0
@@ -0,0 +1,4 @@
0
+class Author < ActiveRecord::Base
0
+ has_many :stories
0
+ acts_as_textiled :blog => :lite_mode
0
+end
...
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
0
@@ -0,0 +1,8 @@
0
+why:
0
+ id: 1
0
+ name: why the lucky stiff
0
+ blog: '"RedHanded":http://redhanded.hobix.com'
0
+defunkt:
0
+ id: 2
0
+ name: Chris Wanstrath
0
+ blog: '"ones zeros majors and minors":http://ozmm.org'
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
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
41
42
43
44
45
46
47
48
49
0
@@ -0,0 +1,49 @@
0
+sandbox:
0
+ id: 1
0
+ author_id: 1
0
+ title: The Thrilling Freaky-Freaky Sandbox Hack
0
+ body: Holy cats, I'm proud to offer you this sensational hack today. For me, this is monumental, as it culminates a number of sundry microhacks from the past few years and gets us a step closer to realizing Try Ruby out in the broader kingdoms. This is the sort of thing that will make you want to post spangly angel GIFs in the comments.
0
+ description: _why announces __Sandbox__
0
+irb:
0
+ id: 2
0
+ author_id: 2
0
+ title: Simpler IRB
0
+ description: __Beautify__ your *IRb* prompt
0
+ body: |
0
+ Sick of that ugly irb prompt? Too much information.
0
+
0
+ $ irb
0
+ irb(main):001:0> "i dont care how deeply nested i yam".nil?
0
+ => false
0
+ Check it. Stick this in your .irbrc:
0
+
0
+ IRB.conf[:PROMPT_MODE] = :SIMPLE
0
+ Now we get a prompt which is, well, simple:
0
+
0
+ $ irb
0
+ >> !!nil
0
+ => false
0
+ Less noise.
0
+textile:
0
+ id: 3
0
+ author_id: 2
0
+ title: I am a fan of Textile.
0
+ description: Chris explains why Textile is useful.
0
+ body: |
0
+ _Textile_ is useful because it makes text _slightly_ easier to *read*.
0
+
0
+ If only it were so *easy* to use in every programming language. In Rails,
0
+ with the help of "acts_as_textiled":http://google.com/search?q=acts_as_textiled,
0
+ it's way easy. Thanks in no small part to %{color:red}RedCloth%, of course.
0
+legalize:
0
+ id: 4
0
+ author_id: 2
0
+ title: This is a bunch of text about things.
0
+ body: |
0
+ Is Textile(TM) the wave of the future? What about acts_as_textiled(C)? It's
0
+ doubtful. Why does Textile(TM) smell like _Python_? Can we do anything to
0
+ fix that? No? Well, I guess there are worse smells - like Ruby. jk.
0
+
0
+ But seriously, ice > water and water < rain. But...nevermind. 1 x 1? 1.
0
+
0
+ "You're a good kid," he said. "Keep it up."
...
 
 
 
 
...
1
2
3
4
0
@@ -0,0 +1,4 @@
0
+class Story < ActiveRecord::Base
0
+ belongs_to :author
0
+ acts_as_textiled :body, :description => :lite_mode
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
0
@@ -0,0 +1,12 @@
0
+# MemoryTestFix
0
+def in_memory_database?
0
+ ENV["RAILS_ENV"] == "test" and
0
+ ActiveRecord::Base.connection.class == ActiveRecord::ConnectionAdapters::SQLiteAdapter and
0
+ Rails::Configuration.new.database_configuration['test']['database'] == ':memory:'
0
+end
0
+
0
+if in_memory_database?
0
+ puts "Creating sqlite in memory database"
0
+ load "#{RAILS_ROOT}/db/schema.rb" # use db agnostic schema by default
0
+# ActiveRecord::Migrator.up('db/migrate') # use migrations
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
0
@@ -0,0 +1,13 @@
0
+ActiveRecord::Schema.define(:version => 0) do
0
+ create_table :stories, :force => true do |t|
0
+ t.column :title, :string
0
+ t.column :description, :string
0
+ t.column :body, :text
0
+ t.column :author_id, :integer
0
+ end
0
+
0
+ create_table :authors, :force => true do |t|
0
+ t.column :name, :string
0
+ t.column :blog, :string
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
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
0
@@ -0,0 +1,35 @@
0
+# borrowed from topfunky and scott barron, thanks
0
+require File.expand_path(File.join(File.dirname(__FILE__), '../../../../config/environment.rb'))
0
+require 'active_record/fixtures'
0
+require File.join(File.dirname(__FILE__), 'fixtures/story')
0
+require File.join(File.dirname(__FILE__), 'fixtures/author')
0
+require File.join(File.dirname(__FILE__), 'memory_test_fix')
0
+require 'test/unit'
0
+
0
+config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
0
+ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
0
+ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
0
+
0
+load(File.dirname(__FILE__) + "/schema.rb")
0
+
0
+Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
0
+$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
0
+
0
+
0
+class Test::Unit::TestCase #:nodoc:
0
+ def create_fixtures(*table_names)
0
+ if block_given?
0
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
0
+ else
0
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
0
+ end
0
+ end
0
+
0
+ # Turn off transactional fixtures if you're working with MyISAM tables in MySQL
0
+ self.use_transactional_fixtures = true
0
+
0
+ # Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
0
+ self.use_instantiated_fixtures = false
0
+
0
+ # Add more helper methods to be used by all tests here...
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
0
@@ -0,0 +1,115 @@
0
+require File.join(File.dirname(__FILE__), 'setup_test')
0
+
0
+class TestTextiled < Test::Unit::TestCase
0
+ fixtures :stories, :authors
0
+
0
+ def test_desc_is_html
0
+ story = Story.find(1)
0
+
0
+ desc_html = '_why announces <i>Sandbox</i>'
0
+ desc_textile = '_why announces __Sandbox__'
0
+ desc_plain = '_why announces Sandbox'
0
+
0
+ assert_equal desc_html, story.description
0
+ assert_equal desc_textile, story.description_source
0
+ assert_equal desc_plain, story.description_plain
0
+ end
0
+
0
+ def test_desc_after_save
0
+ story = Story.find(2)
0
+
0
+ start_html = '<i>Beautify</i> your <strong>IRb</strong> prompt'
0
+ assert_equal start_html, story.description
0
+
0
+ story.description = "**IRb** is simple"
0
+ changed_html = "<b>IRb</b> is simple"
0
+ assert_equal changed_html, story.description
0
+ story.save
0
+ assert_equal changed_html, story.description
0
+ assert_equal 'IRb is simple', story.description_plain
0
+ end
0
+
0
+ def test_desc_toggle_textile
0
+ story = Story.find(2)
0
+
0
+ desc_html = '<i>Beautify</i> your <strong>IRb</strong> prompt'
0
+ desc_textile = '__Beautify__ your *IRb* prompt'
0
+
0
+ assert_equal desc_html, story.description
0
+ story.textiled = false
0
+ assert_equal desc_textile, story.description
0
+ story.save
0
+ assert_equal desc_textile, story.description
0
+ story.textiled = true
0
+ assert_equal desc_html, story.description
0
+ end
0
+
0
+ def test_assocation_textiled
0
+ story = Story.find(2)
0
+
0
+ blog_html = '<a href="http://ozmm.org">ones zeros majors and minors</a>'
0
+ blog_textile = '"ones zeros majors and minors":http://ozmm.org'
0
+ blog_plain = 'ones zeros majors and minors'
0
+
0
+ assert_equal blog_html, story.author.blog
0
+ assert_equal blog_textile, story.author.blog_source
0
+ assert_equal blog_plain, story.author.blog_plain
0
+ end
0
+
0
+ def test_assocation_textile_toggle
0
+ story = Story.find(1)
0
+
0
+ blog_html = '<a href="http://redhanded.hobix.com">RedHanded</a>'
0
+ blog_textile = '"RedHanded":http://redhanded.hobix.com'
0
+ blog_plain = 'RedHanded'
0
+
0
+ assert_equal blog_html, story.author.blog
0
+ story.author.textiled = false
0
+ assert_equal blog_textile, story.author.blog
0
+ story.author.textiled = true
0
+ assert_equal blog_html, story.author.blog
0
+ end
0
+
0
+ def test_body_is_html
0
+ story = Story.find(3)
0
+
0
+ body_html = %[<p><em>Textile</em> is useful because it makes text <em>slightly</em> easier to <strong>read</strong>.</p>\n\n\n\t<p>If only it were so <strong>easy</strong> to use in every programming language. In Rails,\nwith the help of <a href="http://google.com/search?q=acts_as_textiled">acts_as_textiled</a>,\nit&#8217;s way easy. Thanks in no small part to <span style="color:red;">RedCloth</span>, of course.</p>]
0
+ body_textile = %[_Textile_ is useful because it makes text _slightly_ easier to *read*.\n\nIf only it were so *easy* to use in every programming language. In Rails,\nwith the help of "acts_as_textiled":http://google.com/search?q=acts_as_textiled,\nit's way easy. Thanks in no small part to %{color:red}RedCloth%, of course.\n]
0
+ body_plain = %[Textile is useful because it makes text slightly easier to read.\n\n\n\tIf only it were so easy to use in every programming language. In Rails,\nwith the help of acts_as_textiled,\nit's way easy. Thanks in no small part to RedCloth, of course.]
0
+
0
+ assert_equal body_html, story.body
0
+ assert_equal body_textile, story.body_source
0
+ assert_equal body_plain, story.body_plain
0
+ end
0
+
0
+ def test_character_conversions
0
+ story = Story.find(4)
0
+
0
+ body_html = "<p>Is Textile&#8482; the wave of the future? What about acts_as_textiled&#169;? It&#8217;s\ndoubtful. Why does Textile&#8482; smell like <em>Python</em>? Can we do anything to\nfix that? No? Well, I guess there are worse smells &#8211; like Ruby. jk.</p>\n\n\n\t<p>But seriously, ice &gt; water and water &lt; rain. But&#8230;nevermind. 1&#215;1? 1.</p>\n\n\n\t<p>&#8220;You&#8217;re a good kid,&#8221; he said. &#8220;Keep it up.&#8221;</p>"
0
+ body_plain = %[Is Textile(TM) the wave of the future? What about acts_as_textiled(C)? It's\ndoubtful. Why does Textile(TM) smell like Python? Can we do anything to\nfix that? No? Well, I guess there are worse smells-like Ruby. jk.\n\n\n\tBut seriously, ice > water and water < rain. But...nevermind. 1x1? 1.\n\n\n\t"You're a good kid," he said. "Keep it up."]
0
+
0
+ assert_equal body_html, story.body
0
+ assert_equal body_plain, story.body_plain
0
+ end
0
+
0
+ def test_textilize
0
+ story = Story.find(1)
0
+ desc_html = '_why announces <i>Sandbox</i>'
0
+
0
+ assert_equal 0, story.textiled.size
0
+
0
+ story.textilize
0
+
0
+ assert_equal 2, story.textiled.size
0
+ assert_equal desc_html, story.description
0
+ end
0
+
0
+ def test_textilize_after_find
0
+ Story.send(:define_method, :after_find, proc { textilize })
0
+ story = Story.find(2)
0
+ desc_html = '<i>Beautify</i> your <strong>IRb</strong> prompt'
0
+
0
+ assert_equal 2, story.textiled.size
0
+ assert_equal desc_html, story.description
0
+ end
0
+end

Comments

    No one has commented yet.