Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI #80

Merged
merged 4 commits into from
Nov 9, 2017
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Gemfile.lock
.~*
doc
.yardoc
coverage
11 changes: 3 additions & 8 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
Lint/EndAlignment:
AlignWith: variable
AutoCorrect: true

Style/AlignHash:
EnforcedHashRocketStyle: table
EnforcedColonStyle: table

Style/Documentation:
Enabled: false

Expand All @@ -17,3 +9,6 @@ Metrics/LineLength:

Style/FileName:
Enabled: false

Metrics/BlockLength:
Enabled: false
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

16 changes: 11 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq libreoffice-writer

addons:
code_climate:
repo_token: 5d3c17f575317e4b908b8af9e1e44fbc48a4970b14a06c086658c3f1e567b558

cache:
- bundler
- apt

env:
global:
NOKOGIRI_USE_SYSTEM_LIBRARIES=true
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
- CC_TEST_REPORTER_ID=5d3c17f575317e4b908b8af9e1e44fbc48a4970b14a06c086658c3f1e567b558

matrix:
- LIBRE_OFFICE_VERSION=4-4
- LIBRE_OFFICE_VERSION=5-0

before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build

after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec

gem 'codeclimate-test-reporter', group: :test, require: nil
gem 'simplecov', require: false, group: :test
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rubygems'
require 'bundler'
require 'rake'
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test_script:

environment:
matrix:
- ruby_version: "21"
- ruby_version: "22"

artifacts:
- path: install_log.txt
Expand Down
1 change: 1 addition & 0 deletions bin/w2m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'word-to-markdown'

Expand Down
2 changes: 2 additions & 0 deletions lib/cliver/dependency_ext.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'sys/proctable'

module Cliver
Expand Down
2 changes: 2 additions & 0 deletions lib/nokogiri/xml/element.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nokogiri
module XML
class Element
Expand Down
13 changes: 7 additions & 6 deletions lib/word-to-markdown.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'descriptive_statistics'
require 'reverse_markdown'
require 'nokogiri-styles'
Expand All @@ -22,10 +24,10 @@ class WordToMarkdown
REVERSE_MARKDOWN_OPTIONS = {
unknown_tags: :bypass,
github_flavored: true
}
}.freeze

# Minimum version of LibreOffice Required
SOFFICE_VERSION_REQUIREMENT = '> 4.0'
SOFFICE_VERSION_REQUIREMENT = '> 4.0'.freeze

# Paths to look for LibreOffice, in order of preference
PATHS = [
Expand All @@ -34,7 +36,7 @@ class WordToMarkdown
'/Applications/LibreOffice.app/Contents/MacOS',
'/Program Files/LibreOffice 5/program',
'/Program Files (x86)/LibreOffice 4/program'
]
].freeze

# Create a new WordToMarkdown object
#
Expand All @@ -54,17 +56,16 @@ def to_s
end

class << self

# Run an soffice command
#
# @param args [string] one or more arguments to pass to the sofice command
# @return [string] the command output
def run_command(*args)
fail 'LibreOffice already running' if soffice.open?
raise 'LibreOffice already running' if soffice.open?

output, status = Open3.capture2e(soffice.path, *args)
logger.debug output
fail "Command `#{soffice.path} #{args.join(' ')}` failed: #{output}" if status.exitstatus != 0
raise "Command `#{soffice.path} #{args.join(' ')}` failed: #{output}" if status.exitstatus != 0
output
end

Expand Down
6 changes: 4 additions & 2 deletions lib/word-to-markdown/converter.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# encoding: utf-8

# frozen_string_literal: true

class WordToMarkdown
class Converter
attr_reader :document
Expand All @@ -13,7 +15,7 @@ class Converter
MIN_HEADING_SIZE = 20

# Unicode bullets to strip when processing
UNICODE_BULLETS = ['○', 'o', '●', "\u2022", '\\p{C}']
UNICODE_BULLETS = ['○', 'o', '●', "\u2022", '\\p{C}'].freeze

# @param document [WordToMarkdown::Document] The document to convert
def initialize(document)
Expand Down
25 changes: 14 additions & 11 deletions lib/word-to-markdown/document.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# encoding: utf-8

# frozen_string_literal: true

class WordToMarkdown
class Document
class NotFoundError < StandardError; end
class ConversionError < StandardError; end

attr_reader :path, :raw_html, :tmpdir
attr_reader :path, :tmpdir

# @param path [string] Path to the Word document
# @param tmpdir [string] Path to a working directory to use
def initialize(path, tmpdir = nil)
@path = File.expand_path path, Dir.pwd
@tmpdir = tmpdir || Dir.mktmpdir
fail NotFoundError, "File #{@path} does not exist" unless File.exist?(@path)
raise NotFoundError, "File #{@path} does not exist" unless File.exist?(@path)
end

# @return [String] the document's extension
Expand Down Expand Up @@ -56,7 +58,7 @@ def encoding
#
# @return [String] the normalized html
def normalized_html
html = raw_html.force_encoding(encoding)
html = raw_html.dup.force_encoding(encoding)
html = html.encode('UTF-8', invalid: :replace, replace: '')
html = Premailer.new(html, with_html_string: true, input_encoding: 'UTF-8').to_inline_css
html.gsub!(/\n|\r/, ' ') # Remove linebreaks
Expand All @@ -72,12 +74,13 @@ def normalized_html
#
# @return [String] the normalized markdown
def scrub_whitespace(string)
string.gsub!('&nbsp;', ' ') # HTML encoded spaces
string.sub!(/\A[[:space:]]+/, '') # document leading whitespace
string.sub!(/[[:space:]]+\z/, '') # document trailing whitespace
string.gsub!(/([ ]+)$/, '') # line trailing whitespace
string.gsub!(/\n\n\n\n/, "\n\n") # Quadruple line breaks
string.gsub!(/\u00A0/, '') # Unicode non-breaking spaces, injected as tabs
string = string.dup
string.gsub!('&nbsp;', ' ') # HTML encoded spaces
string.sub!(/\A[[:space:]]+/, '') # document leading whitespace
string.sub!(/[[:space:]]+\z/, '') # document trailing whitespace
string.gsub!(/([ ]+)$/, '') # line trailing whitespace
string.gsub!(/\n\n\n\n/, "\n\n") # Quadruple line breaks
string.delete!(' ') # Unicode non-breaking spaces, injected as tabs
string
end

Expand All @@ -91,7 +94,7 @@ def dest_path
def raw_html
@raw_html ||= begin
WordToMarkdown.run_command '--headless', '--convert-to', filter, path, '--outdir', tmpdir
fail ConversionError, "Failed to convert #{path}" unless File.exist?(dest_path)
raise ConversionError, "Failed to convert #{path}" unless File.exist?(dest_path)
html = File.read dest_path
File.delete dest_path
html
Expand Down
4 changes: 3 additions & 1 deletion lib/word-to-markdown/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class WordToMarkdown
VERSION = '1.1.7'
VERSION = '1.1.7'.freeze
end
17 changes: 5 additions & 12 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts 'Run `bundle install` to install missing gems'
exit e.status_code
end
# frozen_string_literal: true

require 'simplecov'
SimpleCov.start

require 'minitest/autorun'
require 'shoulda'
require 'mocha'
require 'mocha/test_unit'
require 'open3'

require 'codeclimate-test-reporter'
CodeClimate::TestReporter.start

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'word-to-markdown'
Expand Down
2 changes: 1 addition & 1 deletion test/test_word_to_markdown.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: utf-8
# frozen_string_literal: true

require File.join(File.dirname(__FILE__), 'helper')

Expand Down
2 changes: 2 additions & 0 deletions test/test_word_to_markdown_cli.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require File.join(File.dirname(__FILE__), 'helper')

class TestWordToMarkdownCli < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/test_word_to_markdown_document.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require File.join(File.dirname(__FILE__), 'helper')

class TestWordToMarkdownDocument < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/test_word_to_markdown_implicit_headings.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require File.join(File.dirname(__FILE__), 'helper')

class TestWordToMarkdownImplicitHeadings < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/test_word_to_markdown_lists.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require File.join(File.dirname(__FILE__), 'helper')

class TestWordToMarkdownLists < Minitest::Test
Expand Down
19 changes: 10 additions & 9 deletions word-to-markdown.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require File.expand_path('../lib/word-to-markdown/version', __FILE__)

Gem::Specification.new do |s|
Expand All @@ -19,20 +21,19 @@ Gem::Specification.new do |s|
'bin/w2m'
]
s.executables = ['w2m']
s.add_dependency('reverse_markdown', '~> 0.6')
s.add_dependency('cliver', '~> 0.3')
s.add_dependency('descriptive_statistics', '~> 2.5')
s.add_dependency('premailer', '~> 1.8')
s.add_dependency('nokogiri-styles', '~> 0.1')
s.add_dependency('premailer', '~> 1.8')
s.add_dependency('reverse_markdown', '~> 0.6')
s.add_dependency('sys-proctable', '~> 0.9')
s.add_dependency('cliver', '~> 0.3')

s.add_development_dependency('rake', '~> 10.4')
s.add_development_dependency('shoulda', '~> 3.5')
s.add_development_dependency('bundler', '~> 1.6')
s.add_development_dependency('pry', '~> 0.10')
s.add_development_dependency('mocha', '~> 1.1')
s.add_development_dependency('minitest', '~> 5.0')
s.add_development_dependency('mocha', '~> 1.1')
s.add_development_dependency('pry', '~> 0.10')
s.add_development_dependency('rake', '~> 10.4')
s.add_development_dependency('rubocop', '~> 0.35')
s.add_development_dependency('yard', "~> 0.8")

s.add_development_dependency('shoulda', '~> 3.5')
s.add_development_dependency('yard', '~> 0.8')
end