Skip to content
This repository was archived by the owner on May 28, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .buildpacks
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://github.com/rcaught/heroku-buildpack-cmake
https://codon-buildpacks.s3.amazonaws.com/buildpacks/frederick/heroku-buildpack-ruby.tgz
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: ruby
rvm:
- jruby-19mode
- 1.9.3
- 2.1.5
# TODO: tests on Ruby 2.2.0
# - 2.2.0
Expand Down
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ source 'https://rubygems.org'
gem 'rails', '4.0.13'
gem 'jquery-rails'
gem 'rails_autolink'
gem 'kramdown'

gem 'qiita-markdown', :platforms => :ruby
gem 'kramdown', :platforms => :jruby

gem 'omniauth-openid'
gem 'erubis'
Expand Down
40 changes: 40 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ GEM
bullet (4.14.0)
activesupport (>= 3.0.0)
uniform_notifier (>= 1.6.0)
charlock_holmes (0.7.3)
childprocess (0.5.5)
ffi (~> 1.0, >= 1.0.11)
choice (0.2.0)
Expand All @@ -51,11 +52,13 @@ GEM
simplecov (>= 0.7)
term-ansicolor
thor
crass (1.0.2)
daemons (1.1.9)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
docile (1.1.5)
erubis (2.7.0)
escape_utils (1.1.0)
eventmachine (1.0.4)
execjs (2.2.2)
factory_girl (4.5.0)
Expand All @@ -64,8 +67,18 @@ GEM
factory_girl (~> 4.5.0)
railties (>= 3.0.0)
ffi (1.9.6-java)
gemoji (2.1.0)
github-linguist (4.5.8)
charlock_holmes (~> 0.7.3)
escape_utils (~> 1.1.0)
mime-types (>= 1.19)
rugged (>= 0.23.0b)
greenmat (3.2.2.1)
hashie (3.3.2)
hike (1.2.3)
html-pipeline (1.11.0)
activesupport (>= 2)
nokogiri (~> 1.4)
i18n (0.7.0)
jdbc-sqlite3 (3.8.7)
jquery-rails (3.1.2)
Expand All @@ -86,8 +99,10 @@ GEM
magic_encoding (0.0.2)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mem (0.1.5)
method_source (0.8.2)
mime-types (2.4.3)
mini_portile (0.6.2)
minitest (4.7.5)
mizuno (0.6.8)
childprocess (>= 0.2.6)
Expand All @@ -96,13 +111,18 @@ GEM
rack (>= 1.0.0)
multi_json (1.10.1)
netrc (0.10.2)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
nokogumbo (1.4.1)
nokogiri
omniauth (1.2.2)
hashie (>= 1.2, < 4)
rack (~> 1.0)
omniauth-openid (1.0.1)
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
pg (0.18.2)
posix-spawn (0.3.11)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
Expand All @@ -114,6 +134,19 @@ GEM
spoon (~> 0.0)
pry-rails (0.3.2)
pry (>= 0.9.10)
pygments.rb (0.6.3)
posix-spawn (~> 0.3.6)
yajl-ruby (~> 1.2.0)
qiita-markdown (0.8.0)
activesupport
gemoji
github-linguist
greenmat (>= 3.2.0.2, < 4)
html-pipeline
mem
pygments.rb
rugged (>= 0.21.1b2)
sanitize
rack (1.5.2)
rack-openid (1.3.1)
rack (>= 1.1.0)
Expand Down Expand Up @@ -154,6 +187,11 @@ GEM
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
ruby-openid (2.6.0)
rugged (0.23.0b4)
sanitize (4.0.0)
crass (~> 1.0.2)
nokogiri (>= 1.4.4)
nokogumbo (= 1.4.1)
simple_form (3.1.0)
actionpack (~> 4.0)
activemodel (~> 4.0)
Expand Down Expand Up @@ -204,6 +242,7 @@ GEM
execjs (>= 0.3.0)
json (>= 1.8.0)
uniform_notifier (1.6.2)
yajl-ruby (1.2.1)

PLATFORMS
java
Expand All @@ -227,6 +266,7 @@ DEPENDENCIES
omniauth-openid
pg
pry-rails
qiita-markdown
rails (= 4.0.13)
rails_autolink
rspec-kickstarter
Expand Down
1 change: 1 addition & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"postdeploy": "bundle exec rake db:create db:migrate"
},
"env": {
"BUILDPACK_URL": "https://github.com/heroku/heroku-buildpack-multi.git",
"BUNDLE_WITHOUT": {
"description": "bundle install --without <these>",
"value": "test:development"
Expand Down
18 changes: 14 additions & 4 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# -*- encoding : utf-8 -*-
require 'kramdown'
begin
require 'kramdown'
rescue LoadError
end

require 'digest/md5'
require 'cgi'

Expand Down Expand Up @@ -47,11 +51,17 @@ def favorite_users(gist)
end

def markdown(md_body)
begin
if defined?(Kramdown)
# JRuby
Kramdown::Document.new(md_body).to_html
rescue Exception
md_body
else
# MRI
processor = Qiita::Markdown::Processor.new
result = processor.call(md_body)
result[:output].to_s.html_safe
end
rescue Exception
md_body
end

def gravatar_image(user, options = {})
Expand Down
35 changes: 33 additions & 2 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ def current_user

describe 'markdown' do
it "doesn't interpret the body when it fails" do
allow_any_instance_of(Kramdown::Document).to receive(:to_html) { raise Kramdown::Error }
if defined?(Kramdown)
# JRuby
allow_any_instance_of(Kramdown::Document).to receive(:to_html) { raise Kramdown::Error }
else
# MRI
allow_any_instance_of(Qiita::Markdown::Processor).to receive(:call) { raise "Some error" }
end

md_body = "Simulating error thrown by Kramdown"

expect(markdown(md_body)).to eq(md_body)
Expand All @@ -97,7 +104,11 @@ def current_user
- c
EOF
result = markdown(md_body)
expected = <<EOF

expected =
if defined?(Kramdown)
# JRuby
<<EOF
<h1 id="foo">foo</h1>

<p>Something!</p>
Expand All @@ -110,6 +121,26 @@ def current_user
<li>c</li>
</ul>
EOF
else
# MRI
<<EOF

<h1>
<span id="foo" class="fragment"></span><a href="#foo"><i class="fa fa-link"></i></a>foo</h1>

<p>Something!</p>

<h2>
<span id="bar" class="fragment"></span><a href="#bar"><i class="fa fa-link"></i></a>Bar</h2>

<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
EOF
end

expect(result).to eq(expected)
end
end
Expand Down