Skip to content
Browse files

raw_content/rc helper. This displays raw markdown content. Fixes #1.

  • Loading branch information...
1 parent c4fbbc9 commit 41a42d81a8186a11b48a83dea590a35a9aa7d44b @lunks lunks committed Aug 23, 2012
Showing with 34 additions and 1 deletion.
  1. +5 −0 app/helpers/content_helper.rb
  2. +12 −1 app/models/content.rb
  3. +6 −0 spec/helpers/content_helper_spec.rb
  4. +11 −0 spec/models/content_spec.rb
View
5 app/helpers/content_helper.rb
@@ -3,4 +3,9 @@ def content(*args)
Content.from_slug(*args).parsed_text
end
alias :c :content
+
+ def raw_content(*args)
+ Content.from_slug(*args).raw_text
+ end
+ alias :rc :raw_content
end
View
13 app/models/content.rb
@@ -5,8 +5,19 @@ class Content < ActiveRecord::Base
validates_uniqueness_of :slug
def parsed_text
- RDiscount.new(text).to_html.html_safe
+ markdown.to_html.html_safe
end
+
+ def raw_text
+ text.html_safe
+ end
+
+ def markdown
+ @content ||= RDiscount.new(text)
+ end
+
+
+
class << self
def from_slug(slug, options={})
raise NoDefaultContentError if options[:default].nil?
View
6 spec/helpers/content_helper_spec.rb
@@ -11,4 +11,10 @@
it "should have an alias as c" do
helper.c(@options).should == "<p>Hi, this is dog</p>\n"
end
+ it "returns a raw content by slug" do
+ helper.raw_content(@options).should == "Hi, this is dog"
+ end
+ it "should have an alias as rc" do
+ helper.rc(@options).should == "Hi, this is dog"
+ end
end
View
11 spec/models/content_spec.rb
@@ -53,4 +53,15 @@
@content.parsed_text.should be_html_safe
end
end
+ context "using raw content" do
+ before do
+ @content = Content.create({slug: :my_already_created_slug, text: "#Hi, this is dog!"}, as: :admin)
+ end
+ it "displays the markdown tags" do
+ @content.raw_text.should == "#Hi, this is dog!"
+ end
+ it "is html safe" do
+ @content.raw_text.should be_html_safe
+ end
+ end
end

0 comments on commit 41a42d8

Please sign in to comment.
Something went wrong with that request. Please try again.