markdown_presenter 0.5.7 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/markdown_presenter.rb +33 -2
  3. metadata +58 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f41bf3cbda7d4f5d9c3d487b3666c281c0e2e972
4
- data.tar.gz: f1b9b826e8b0d3a03178f5b441d37b97e45b7061
3
+ metadata.gz: 2e0f76e3b85122c82c27e93edbfb226b8dd0e22e
4
+ data.tar.gz: cdf2edbed93f4f4a2bcf05c1a94e96aa86e477ef
5
5
  SHA512:
6
- metadata.gz: b2af2d7281302b089c24baedf390b80267f71ddbe68de2df728e55b4ec177c9a59503163062a8633333da474c995de1fba36f00d6810a00035f092769596eb04
7
- data.tar.gz: 21619afcdd8c207813efe137d25c92ba6e32417f632dfdc5dc5eb09cfa9dd4396c05fd299346e0fd99ed44fdebb5828a15e7c90da9bdbe266aed099b92a097de
6
+ metadata.gz: fd5ffbbc9f3bb9e94a260fe7f9a1f67dbb02e3ff7b1428af18eac8d9940596629b01678abc4ee159cc206a6108542d46e5ce05588acbe5e2e718800ba7f954ea
7
+ data.tar.gz: d9276ce559af73f0edc3838a2ca73a5528fdc2e5d1bfd036605c540596efddb712e01032471fdeb5908ae799fcd2798e16b91dd057a8594caa372098e56e86b8
@@ -2,6 +2,10 @@
2
2
 
3
3
  require 'haml'
4
4
  require 'kramdown'
5
+ require 'nokogiri'
6
+ require 'open-uri'
7
+ require 'base64'
8
+ require 'mime/types'
5
9
 
6
10
  def present title, content
7
11
  template = File.read(File.join(File.dirname(__FILE__), "../presenter.html.haml"))
@@ -27,8 +31,35 @@ def content_of filename
27
31
  end
28
32
  end
29
33
 
34
+ def data_uri_for url
35
+ begin
36
+ response = open(url)
37
+ encoded_image = Base64.encode64 response.read
38
+ content_type = response.respond_to?(:meta) ? response.meta['content-type'] : MIME::Types.type_for(url[-3..url.size]).first.content_type
39
+ "data:#{content_type};base64,#{encoded_image}"
40
+ rescue
41
+ $stderr.puts "WARNING: An exception occurred trying to construct a data URI. We will fall back to the original URL.", $!, $!.backtrace
42
+ url
43
+ end
44
+ end
45
+
46
+ def embed content
47
+ doc = Nokogiri::HTML(content)
48
+ tags_and_attributes = [['img', 'src'], ['link','href'], ['script', 'src']]
49
+ tags_and_attributes.each do |tag_name, src|
50
+ doc.css(tag_name).each do |tag|
51
+ tag[src] = data_uri_for tag[src]
52
+ end
53
+ end
54
+ doc.css("body").inner_html
55
+ end
56
+
30
57
  def process filename
31
- puts present(filename, content_of(filename))
58
+ puts present(filename, embed(content_of(filename)))
32
59
  end
33
60
 
34
- process ARGV[0] if __FILE__ == $0
61
+ if __FILE__ == $0
62
+ ($stderr.puts "Specify a filename in argument."; exit 1) if ARGV.empty?
63
+
64
+ process ARGV[0]
65
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Tanguay-Carel
@@ -9,7 +9,63 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-01-16 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: haml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: kramdown
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mime-types
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
13
69
  description: Transforms a markdown file into an HTML presentation
14
70
  email: matthieutc@gmail.com
15
71
  executables: