markdownable 0.0.1 → 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.
- data/lib/markdownable/version.rb +1 -1
- data/lib/markdownable.rb +10 -7
- data/spec/models/article_spec.rb +5 -0
- data/spec/poro_spec.rb +8 -3
- metadata +3 -3
data/lib/markdownable/version.rb
CHANGED
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
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
data/spec/models/article_spec.rb
CHANGED
@@ -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
|
14
|
+
@article.title = nil
|
15
15
|
@article.author = "Aaron Cruz"
|
16
|
-
@article.body
|
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.
|
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: -
|
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: -
|
173
|
+
hash: -1065785926261125110
|
174
174
|
requirements: []
|
175
175
|
rubyforge_project:
|
176
176
|
rubygems_version: 1.8.23
|