diff --git a/Gemfile.lock b/Gemfile.lock index 713405e1..15b8b39d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,6 +7,7 @@ PATH coffee-script (~> 2.4.1) compass (~> 1.0.3) dragonfly (~> 1.0.12) + github-markup (~> 1.4.0) haml (~> 4.0.6) httparty (~> 0.13.6) kramdown (~> 1.8.0) @@ -44,7 +45,7 @@ GEM columnize (= 0.9.0) chronic (0.10.2) chunky_png (1.3.5) - codeclimate-test-reporter (0.4.7) + codeclimate-test-reporter (0.4.8) simplecov (>= 0.7.1, < 1.0.0) coderay (1.1.0) coffee-script (2.4.1) @@ -66,16 +67,17 @@ GEM sass (>= 3.3.0, < 3.5) compass-import-once (1.0.5) sass (>= 3.2, < 3.5) - coveralls (0.8.1) + coveralls (0.8.9) json (~> 1.8) rest-client (>= 1.6.8, < 2) simplecov (~> 0.10.0) term-ansicolor (~> 1.3) thor (~> 0.19.1) + tins (~> 1.6.0) crass (1.0.2) diff-lcs (1.2.5) docile (1.1.5) - domain_name (0.5.24) + domain_name (0.5.25) unf (>= 0.0.5, < 1.0.0) dragonfly (1.0.12) addressable (~> 2.3) @@ -88,6 +90,7 @@ GEM ffi (1.9.10) flamegraph (0.1.0) fast_stack + github-markup (1.4.0) haml (4.0.7) tilt hike (1.2.3) @@ -116,9 +119,9 @@ GEM attr_extras (~> 4.4.0) colorize stringex (~> 2.5.2) - memory_profiler (0.9.4) + memory_profiler (0.9.6) method_source (0.8.2) - mime-types (2.6.1) + mime-types (2.6.2) mimetype-fu (0.1.2) mini_portile (0.6.2) minitest (5.8.3) @@ -126,26 +129,26 @@ GEM mongo (2.1.2) bson (~> 3.0) morphine (0.1.1) - multi_json (1.11.1) + multi_json (1.11.2) multi_xml (0.5.5) - netrc (0.10.3) + netrc (0.11.0) nokogiri (1.6.6.4) mini_portile (~> 0.6.0) nokogumbo (1.4.1) nokogiri origin (2.1.1) - pry (0.10.1) + pry (0.10.3) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) pry-byebug (3.1.0) byebug (~> 4.0) pry (~> 0.10) - puma (2.12.3) - rack (1.6.1) + puma (2.15.3) + rack (1.6.4) rack-cache (1.5.1) rack (>= 0.4) - rack-mini-profiler (0.9.7) + rack-mini-profiler (0.9.8) rack (>= 1.1.3) rack-rewrite (1.5.1) rack-test (0.6.3) @@ -166,12 +169,12 @@ GEM rspec-core (~> 3.3.0) rspec-expectations (~> 3.3.0) rspec-mocks (~> 3.3.0) - rspec-core (3.3.0) + rspec-core (3.3.2) rspec-support (~> 3.3.0) - rspec-expectations (3.3.0) + rspec-expectations (3.3.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.3.0) - rspec-mocks (3.3.0) + rspec-mocks (3.3.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.3.0) rspec-support (3.3.0) @@ -199,13 +202,13 @@ GEM tilt (~> 1.1) stackprof (0.2.7) stringex (2.5.2) - term-ansicolor (1.3.0) + term-ansicolor (1.3.2) tins (~> 1.0) thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) timecop (0.7.4) - tins (1.5.2) + tins (1.6.0) tzinfo (1.2.2) thread_safe (~> 0.1) unf (0.1.4) diff --git a/lib/locomotive/steam/liquid/filters/text.rb b/lib/locomotive/steam/liquid/filters/text.rb index 2e6b1162..aeaf00bb 100644 --- a/lib/locomotive/steam/liquid/filters/text.rb +++ b/lib/locomotive/steam/liquid/filters/text.rb @@ -45,6 +45,10 @@ def markdown(input) @context.registers[:services].markdown.to_html(input) end + def rst(input) + @context.registers[:services].rst.to_html(input) + end + end ::Liquid::Template.register_filter(Text) diff --git a/lib/locomotive/steam/liquid/tags/editable/text.rb b/lib/locomotive/steam/liquid/tags/editable/text.rb index ac426609..8f260af9 100644 --- a/lib/locomotive/steam/liquid/tags/editable/text.rb +++ b/lib/locomotive/steam/liquid/tags/editable/text.rb @@ -14,7 +14,6 @@ def render_element(context, element) else element.content end - format_content(content, element.format, context) end end @@ -22,6 +21,7 @@ def render_element(context, element) def format_content(content, format, context) case format when 'markdown' then markdown_service(context).to_html(content) + when 'rst' then rst_service(context).to_html(content) else content end @@ -57,6 +57,10 @@ def markdown_service(context) context.registers[:services].markdown end + def rst_service(context) + context.registers[:services].rst + end + end ::Liquid::Template.register_tag('editable_text'.freeze, Text) diff --git a/lib/locomotive/steam/services.rb b/lib/locomotive/steam/services.rb index 43f2650d..8e707eb9 100644 --- a/lib/locomotive/steam/services.rb +++ b/lib/locomotive/steam/services.rb @@ -102,6 +102,10 @@ class Instance Steam::MarkdownService.new end + register :rst do + Steam::RstService.new + end + register :textile do Steam::TextileService.new end diff --git a/lib/locomotive/steam/services/rst_service.rb b/lib/locomotive/steam/services/rst_service.rb new file mode 100644 index 00000000..fa68a497 --- /dev/null +++ b/lib/locomotive/steam/services/rst_service.rb @@ -0,0 +1,17 @@ +require 'github/markup' + +module Locomotive + module Steam + + class RstService + + def to_html(text) + return '' if text.blank? + + GitHub::Markup.render(".rst", text) + end + + end + + end +end diff --git a/locomotivecms_steam.gemspec b/locomotivecms_steam.gemspec index e8bc982d..961c1134 100644 --- a/locomotivecms_steam.gemspec +++ b/locomotivecms_steam.gemspec @@ -41,6 +41,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'kramdown', '~> 1.8.0' spec.add_dependency 'RedCloth', '~> 4.2.9' + spec.add_dependency 'github-markup', '~> 1.4.0' spec.add_dependency 'haml', '~> 4.0.6' spec.add_dependency 'mimetype-fu', '~> 0.1.2' spec.add_dependency 'mime-types', '~> 2.6.1' diff --git a/spec/unit/liquid/tags/editable/text_spec.rb b/spec/unit/liquid/tags/editable/text_spec.rb index 7b8ab450..afaa4dd3 100644 --- a/spec/unit/liquid/tags/editable/text_spec.rb +++ b/spec/unit/liquid/tags/editable/text_spec.rb @@ -134,6 +134,13 @@ end + context 'rst format' do + + let(:element) { instance_double('EditableText', content: "Hello world!\n============\nLorem ipsum", default_content?: false, format: 'rst') } + it { is_expected.to eq "

Hello world!

\n

Lorem ipsum

\n\n" } + + end + context 'inline-editing mode' do let(:live_editing) { true } diff --git a/spec/unit/services/rst_service_spec.rb b/spec/unit/services/rst_service_spec.rb new file mode 100644 index 00000000..26e2190f --- /dev/null +++ b/spec/unit/services/rst_service_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +describe Locomotive::Steam::RstService do + + let(:service) { described_class.new } + + describe '#to_html' do + + let(:text) { <<-EOF +Hello world! +============ +Lorem ipsum + EOF + } + + subject { service.to_html(text) } + + it do + is_expected.to eq <<-EOF +

Hello world!

+

Lorem ipsum

+ + EOF + end + + describe 'no text' do + + let(:text) { nil } + it { is_expected.to eq '' } + end + + end + +end