Explorar o código

Support for markdown on scenario description.

Guilherme J. Tramontina %!s(int64=10) %!d(string=hai) anos
pai
achega
13a317804f

+ 1 - 1
Gemfile

@@ -85,6 +85,7 @@ gem 'feed-normalizer'
 gem 'slack-notifier', '~> 0.5.0'
 gem 'therubyracer', '~> 0.12.1'
 gem 'mqtt'
+gem 'redcarpet', '~> 3.1.1'
 
 group :development do
   gem 'binding_of_caller'
@@ -123,4 +124,3 @@ else
   gem 'unicorn', platform: :ruby_18
   gem 'rails_12factor', platform: :ruby_18
 end
-

+ 2 - 0
Gemfile.lock

@@ -233,6 +233,7 @@ GEM
       thor (>= 0.18.1, < 2.0)
     raindrops (0.13.0)
     rake (10.3.2)
+    redcarpet (3.1.2)
     ref (1.0.5)
     rest-client (1.6.7)
       mime-types (>= 1.16)
@@ -404,6 +405,7 @@ DEPENDENCIES
   rack
   rails (= 4.1.4)
   rails_12factor
+  redcarpet (~> 3.1.1)
   rr
   rspec (~> 2.99)
   rspec-collection_matchers

+ 8 - 0
app/helpers/markdown_helper.rb

@@ -0,0 +1,8 @@
+module MarkdownHelper
+
+  def markdown(text)
+    markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
+    markdown.render(text).html_safe
+  end
+
+end

+ 1 - 1
app/views/scenarios/show.html.erb

@@ -6,7 +6,7 @@
       </div>
 
       <% if @scenario.description.present? %>
-        <blockquote><%= @scenario.description %></blockquote>
+        <blockquote><%= markdown(@scenario.description) %></blockquote>
       <% end %>
 
       <%= render 'agents/table', :returnTo => scenario_path(@scenario) %>

+ 14 - 0
spec/helpers/markdown_helper_spec.rb

@@ -0,0 +1,14 @@
+require 'spec_helper'
+
+describe MarkdownHelper do
+
+  describe '#markdown' do
+
+    it 'renders HTML from a markdown text' do
+      markdown('# Header').should =~ /<h1>Header<\/h1>/
+      markdown('## Header 2').should =~ /<h2>Header 2<\/h2>/
+    end
+
+  end
+
+end