markdownable 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Markdownable
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/markdownable.rb CHANGED
@@ -3,13 +3,16 @@ require 'markdownable/version'
3
3
 
4
4
  module Markdownable
5
5
  module ClassMethods
6
- def markdownable field
7
- define_method "#{field}_markdown" do
8
- renderer = Redcarpet::Render::HTML.new(:hard_wrap => true)
9
- markdown = Redcarpet::Markdown.new(renderer,
10
- :autolink => true,
11
- :lax_html_blocks => true)
12
- markdown.render(self.send field)
6
+ def markdownable(*fields)
7
+ fields.each do |field|
8
+ define_method "#{field}_markdown" do
9
+ renderer = Redcarpet::Render::HTML.new(:hard_wrap => true)
10
+ markdown = Redcarpet::Markdown.new(renderer,
11
+ :autolink => true,
12
+ :lax_html_blocks => true)
13
+ text = self.send(field)
14
+ markdown.render(text) unless text.nil?
15
+ end
13
16
  end
14
17
  end
15
18
  end
@@ -4,4 +4,9 @@ describe Article do
4
4
  subject { Article.create(:title => "My Article", :author => "Aaron Cruz", :body => "## Hello world")}
5
5
  it { should be_valid }
6
6
  its(:body_markdown) { should =~ /<h2>Hello world<\/h2>/ }
7
+ it "should return nil for nil property" do
8
+ article = Article.create(:title => "My Article", :author => "Aaron Cruz")
9
+ article.body.should be_nil
10
+ article.body_markdown.should be_nil
11
+ end
7
12
  end
data/spec/poro_spec.rb CHANGED
@@ -5,16 +5,21 @@ require 'rspec/autorun'
5
5
  class Article
6
6
  include Markdownable
7
7
  attr_accessor :title, :author, :body
8
- markdownable :body
8
+ markdownable :body, :title
9
9
  end
10
10
 
11
11
  describe "PORO with markdownable" do
12
12
  before(:each) do
13
13
  @article = Article.new
14
- @article.title = "My Article"
14
+ @article.title = nil
15
15
  @article.author = "Aaron Cruz"
16
- @article.body = "## Hello world"
16
+ @article.body = "## Hello world"
17
17
  end
18
18
  subject { @article }
19
19
  its(:body_markdown) { should =~ /<h2>Hello world<\/h2>/ }
20
+
21
+ it "should return nil for nil property" do
22
+ @article.title.should be_nil
23
+ @article.title_markdown.should be_nil
24
+ end
20
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdownable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -161,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
161
161
  version: '0'
162
162
  segments:
163
163
  - 0
164
- hash: -3190620955287273259
164
+ hash: -1065785926261125110
165
165
  required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  none: false
167
167
  requirements:
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  version: '0'
171
171
  segments:
172
172
  - 0
173
- hash: -3190620955287273259
173
+ hash: -1065785926261125110
174
174
  requirements: []
175
175
  rubyforge_project:
176
176
  rubygems_version: 1.8.23