From 3e872f6be97dddb2b5104c67fce46fa8dca3539d Mon Sep 17 00:00:00 2001 From: sue445 Date: Sat, 11 Jul 2015 23:45:12 +0900 Subject: [PATCH 1/3] Use qiita-markdown instead of kramdown when MRI --- Gemfile | 4 ++- Gemfile.lock | 40 +++++++++++++++++++++++++ app/helpers/application_helper.rb | 18 ++++++++--- spec/helpers/application_helper_spec.rb | 35 ++++++++++++++++++++-- 4 files changed, 90 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index c89136d..5d1f37a 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 08852f0..81bd2e9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -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) @@ -96,6 +111,10 @@ 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) @@ -103,6 +122,7 @@ GEM 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) @@ -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) @@ -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) @@ -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 @@ -227,6 +266,7 @@ DEPENDENCIES omniauth-openid pg pry-rails + qiita-markdown rails (= 4.0.13) rails_autolink rspec-kickstarter diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 78ff31c..ca3cd2d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,9 @@ # -*- encoding : utf-8 -*- -require 'kramdown' +begin + require 'kramdown' +rescue LoadError +end + require 'digest/md5' require 'cgi' @@ -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 = {}) diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index d2568c4..19fbfce 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -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) @@ -97,7 +104,11 @@ def current_user - c EOF result = markdown(md_body) - expected = <foo

Something!

@@ -110,6 +121,26 @@ def current_user
  • c
  • EOF + else + # MRI + < +foo + +

    Something!

    + +

    +Bar

    + +
      +
    • a
    • +
    • b
    • +
    • c
    • +
    +EOF + end + expect(result).to eq(expected) end end From 5e93e4b80ad4b9b8218d0002eb7436aadff15f43 Mon Sep 17 00:00:00 2001 From: sue445 Date: Sun, 12 Jul 2015 00:30:17 +0900 Subject: [PATCH 2/3] Use speficied heroku buildpack for build rugged and charlock_holmes http://qiita.com/kwappa/items/aa577c0baeb46d22a9be --- .buildpacks | 2 ++ app.json | 1 + 2 files changed, 3 insertions(+) create mode 100644 .buildpacks diff --git a/.buildpacks b/.buildpacks new file mode 100644 index 0000000..4135db3 --- /dev/null +++ b/.buildpacks @@ -0,0 +1,2 @@ +https://github.com/rcaught/heroku-buildpack-cmake +https://codon-buildpacks.s3.amazonaws.com/buildpacks/frederick/heroku-buildpack-ruby.tgz diff --git a/app.json b/app.json index a8a2066..9267216 100644 --- a/app.json +++ b/app.json @@ -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 ", "value": "test:development" From bb099428a04584ab37b252470a7a045811e65148 Mon Sep 17 00:00:00 2001 From: sue445 Date: Sun, 12 Jul 2015 01:23:40 +0900 Subject: [PATCH 3/3] Drop ruby 1.9 qiita-markdown support only ruby 2.x+ --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 76e46e0..60e05fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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