Permalink
Browse files

Merge branch 'release-0.1.9'

  • Loading branch information...
2 parents 359802c + e98b943 commit 35af280dc50cf3e141ae88565cbfbc9da5f0dfea @walle committed Jul 10, 2011
Showing with 41 additions and 25 deletions.
  1. +1 −2 .gitignore
  2. +10 −0 README.textile
  3. +13 −13 gimli.gemspec
  4. +5 −4 lib/gimli/converter.rb
  5. +1 −1 lib/gimli/version.rb
  6. +11 −5 spec/gimli/converter_spec.rb
View
@@ -1,6 +1,5 @@
pkg/
doc/
.yardoc/
-
-
Gemfile.lock
+.DS_Store
View
@@ -17,6 +17,16 @@ h3. Markup
Markup files may be written in any format supported by GitHub-Markup (except roff).
+h3. Images
+
+Images can be included by absolute url on your hard drive or a absolute url on the Internet. You can also refer to an image relative from the markup file. Example in textile.
+
+<pre>
+!/tmp/test.jpg!
+!http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png!
+!../images/test.jpg!
+</pre>
+
h2. Installation
The best way to install Gimli is with RubyGems:
View
@@ -17,19 +17,19 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--charset=UTF-8"]
s.extra_rdoc_files = %w[README.textile LICENSE]
- s.add_dependency 'github-markup'
- s.add_dependency 'redcarpet'
- s.add_dependency 'RedCloth'
- s.add_dependency 'org-ruby'
- s.add_dependency 'creole'
- s.add_dependency 'wikicloth'
-
- s.add_dependency 'albino'
- s.add_dependency 'nokogiri'
-
- s.add_dependency 'wkhtmltopdf-binary'
- s.add_dependency 'pdfkit'
- s.add_dependency 'optiflag'
+ s.add_dependency 'github-markup', '~> 0.5.3'
+ s.add_dependency 'redcarpet', '~> 1.17.2'
+ s.add_dependency 'RedCloth', '~> 4.2.7'
+ s.add_dependency 'org-ruby', '~> 0.5.3'
+ s.add_dependency 'creole', '~> 0.4.2'
+ s.add_dependency 'wikicloth', '~> 0.6.3'
+
+ s.add_dependency 'albino', '~> 1.3.3'
+ s.add_dependency 'nokogiri', '~> 1.4.4'
+
+ s.add_dependency 'wkhtmltopdf-binary', '~> 0.9.5.3'
+ s.add_dependency 'pdfkit', '~> 0.5.2'
+ s.add_dependency 'optiflag', '~> 0.7'
s.add_development_dependency 'rspec'
s.add_development_dependency 'rr'
@@ -12,7 +12,7 @@ module Gimli
class Converter
# Initialize the converter with a File
- # @param [Array] files The list of Gimli::File to convert (passing a single file will still work)
+ # @param [Array] files The list of Gimli::MarkupFile to convert (passing a single file will still work)
def initialize(files)
@files = files
end
@@ -23,7 +23,7 @@ def convert!(merge = false)
merged_contents = []
@files.each do |file|
markup = Markup.new file
- html = convert_image_urls markup.render
+ html = convert_image_urls markup.render, file.filename
if merge
html = "<div class=\"page-break\"></div>#{html}" unless merged_contents.empty?
merged_contents << html
@@ -41,9 +41,10 @@ def convert!(merge = false)
# Rewrite relative image urls to absolute
# @param [String] html some html to parse
# @return [String] the html with all image urls replaced to absolute
- def convert_image_urls(html)
+ def convert_image_urls(html, filename)
+ dir_string = ::File.dirname(::File.expand_path(filename))
html.scan(/<img[^>]+src="([^"]+)"/).each do |url|
- html.gsub!(url[0], ::File.expand_path(url[0])) unless url[0] =~ /^https?/
+ html.gsub!(url[0], ::File.expand_path(url[0], dir_string)) unless url[0] =~ /^https?/
end
html
@@ -2,7 +2,7 @@
module Gimli
- Version = "0.1.8"
+ Version = "0.1.9"
end
@@ -84,31 +84,37 @@
it 'should convert relative image urls to absolute' do
file = Gimli::MarkupFile.new 'fake'
+ filename = 'fixtures/fake.textile'
+ dir_string = ::File.dirname(::File.expand_path(filename))
converter = Gimli::Converter.new file
html = '<p>foo</p><img src="test.jpg" alt="" /><p>bar</p><img src="test2.jpg" alt="" />'
- valid_html = "<p>foo</p><img src=\"#{File.expand_path('test.jpg')}\" alt=\"\" /><p>bar</p><img src=\"#{File.expand_path('test2.jpg')}\" alt=\"\" />"
+ valid_html = "<p>foo</p><img src=\"#{File.expand_path('test.jpg', dir_string)}\" alt=\"\" /><p>bar</p><img src=\"#{File.expand_path('test2.jpg', dir_string)}\" alt=\"\" />"
- converter.convert_image_urls(html).should == valid_html
+ converter.convert_image_urls(html, filename).should == valid_html
end
it 'should not rewrite non relative urls' do
file = Gimli::MarkupFile.new 'fake'
+ filename = '../../fixtures/fake.textile'
+ dir_string = ::File.dirname(::File.expand_path(filename))
converter = Gimli::Converter.new file
html = '<p>foo</p><img src="https://d3nwyuy0nl342s.cloudfront.net/images/modules/header/logov3-hover.png" alt="" /><p>bar</p>'
- converter.convert_image_urls(html).should == html
+ converter.convert_image_urls(html, filename).should == html
end
it 'should work on both absolute and relative images' do
file = Gimli::MarkupFile.new 'fake'
+ filename = '../../fixtures/fake.textile'
+ dir_string = ::File.dirname(::File.expand_path(filename))
converter = Gimli::Converter.new file
html = '<p>foo</p><img src="test.jpg" alt="" /><p>bar</p><img src="/tmp/test2.jpg" alt="" /> <img src="https://d3nwyuy0nl342s.cloudfront.net/images/modules/header/logov3-hover.png" alt="" />'
- valid_html = "<p>foo</p><img src=\"#{File.expand_path('test.jpg')}\" alt=\"\" /><p>bar</p><img src=\"/tmp/test2.jpg\" alt=\"\" /> <img src=\"https://d3nwyuy0nl342s.cloudfront.net/images/modules/header/logov3-hover.png\" alt=\"\" />"
+ valid_html = "<p>foo</p><img src=\"#{File.expand_path('test.jpg', dir_string)}\" alt=\"\" /><p>bar</p><img src=\"/tmp/test2.jpg\" alt=\"\" /> <img src=\"https://d3nwyuy0nl342s.cloudfront.net/images/modules/header/logov3-hover.png\" alt=\"\" />"
- converter.convert_image_urls(html).should == valid_html
+ converter.convert_image_urls(html, filename).should == valid_html
end
end

0 comments on commit 35af280

Please sign in to comment.