Skip to content

Commit

Permalink
added rst format via github-markup gem
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalyi committed Nov 29, 2015
1 parent f005060 commit a7fd35f
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 17 deletions.
35 changes: 19 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -116,36 +119,36 @@ 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)
moneta (0.8.0)
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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions lib/locomotive/steam/liquid/filters/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion lib/locomotive/steam/liquid/tags/editable/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def render_element(context, element)
else
element.content
end

format_content(content, element.format, context)
end
end

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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions lib/locomotive/steam/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class Instance
Steam::MarkdownService.new
end

register :rst do
Steam::RstService.new
end

register :textile do
Steam::TextileService.new
end
Expand Down
17 changes: 17 additions & 0 deletions lib/locomotive/steam/services/rst_service.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions locomotivecms_steam.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions script/ci/before_build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
echo 'America/Chicago' | sudo tee /etc/timezone
sudo dpkg-reconfigure --frontend noninteractive tzdata
sudo pip install docutils
date
7 changes: 7 additions & 0 deletions spec/unit/liquid/tags/editable/text_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<h1 class=\"title\">Hello world!</h1>\n<p>Lorem ipsum</p>\n\n" }

end

context 'inline-editing mode' do

let(:live_editing) { true }
Expand Down
34 changes: 34 additions & 0 deletions spec/unit/services/rst_service_spec.rb
Original file line number Diff line number Diff line change
@@ -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
<h1 class="title">Hello world!</h1>
<p>Lorem ipsum</p>
EOF
end

describe 'no text' do

let(:text) { nil }
it { is_expected.to eq '' }
end

end

end

0 comments on commit a7fd35f

Please sign in to comment.