publishr 0.5.9 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,7 +31,7 @@ if ARGV[0].nil?
31
31
  puts ''
32
32
  puts " [name] is an unique string that identifies your project. Rendered files will be named after this."
33
33
  puts " [path_to_source_dir] directory must minimally contain: [cover.jpg, covertext.txt, frontmatter.txt, toc.txt, metadata.yml]"
34
- puts " [format] must be {mobi, epub, pdf}"
34
+ puts " [format] must be {kindle, pdf}"
35
35
  puts " [path_to_converters] directory must contain `kindlegen` and `jpg2ps`. They cannot be shipped with this program due to legal reasons."
36
36
  puts ''
37
37
  puts 'EXAMPLE: publishr mybook1 my/files/mybook epub path/to/converters'
@@ -51,3 +51,5 @@ case ARGV[2]
51
51
  when 'kindle' then project.make_kindle
52
52
  when 'pdf' then project.make_pdf
53
53
  end
54
+
55
+ #project.make_images_local("abc ![alt](http://www.sott.net/image/image/s1/33868/medium/sott_6percent_sm.jpg) \n ;lkjsdflk \n xxx ![alt](http://billgastro.com/images/header-en.png)")
@@ -22,7 +22,7 @@ module Publishr
22
22
  @inpath = inpath
23
23
  @outpath = outpath
24
24
  @metadata = metadata
25
- @gempath = Publishr::gempath
25
+ @gempath = Publishr::Project.gempath
26
26
  @rails_resources_url = rails_resources_url
27
27
 
28
28
  @html_files = []
@@ -20,7 +20,7 @@ module Publishr
20
20
  end
21
21
 
22
22
  def self.sanitize(html)
23
- Sanitize.clean(html, :elements => ['b','i','code','br','var','p','blockquote'])
23
+ Sanitize.clean(html, :elements => ['b','i','code','br','var','p','blockquote','img'], :attributes => { 'img' => ['src', 'alt'] })
24
24
  end
25
25
 
26
26
  def degrade
@@ -1,15 +1,11 @@
1
1
  module Publishr
2
2
  class KramdownProcessor
3
- def self.convert(html)
3
+ def self.convert(html,image_url_prefix)
4
4
  sanitized_html = HtmlProcessor.sanitize(html)
5
- lines = Kramdown::Document.new(sanitized_html, :input => 'html', :line_width => 100000 ).to_kramdown.split("\n")
6
- processed_lines = []
7
- lines.each do |line|
8
- line.gsub! '\"', '"'
9
- line.gsub! "\\'", "'"
10
- processed_lines << line
11
- end
12
- processed_lines.join("\n")
5
+ kramdown = Kramdown::Document.new(sanitized_html, :input => 'html', :line_width => 100000 ).to_kramdown
6
+ kramdown.gsub!(/\!\[(.*?)\]\((.*?)\)/){ "![#{$1}](#{image_url_prefix}#{$2})" }
7
+ kramdown.gsub! '\"', '"'
8
+ kramdown.gsub! "\\'", "'"
13
9
  end
14
10
  end
15
11
  end
@@ -21,7 +21,7 @@ module Publishr
21
21
  @name = name
22
22
  @inpath = path
23
23
  @outpath = File.join(@inpath,'latex')
24
- @gempath = Publishr::gempath
24
+ @gempath = Publishr::Project.gempath
25
25
  end
26
26
 
27
27
  def render
@@ -17,11 +17,11 @@
17
17
 
18
18
  module Publishr
19
19
 
20
- mattr_accessor :gempath
21
- @@gempath = File.expand_path('../../../', __FILE__)
20
+ #mattr_accessor :gempath
21
+ #@@gempath = File.expand_path('../../../', __FILE__)
22
22
 
23
23
  class Project
24
- def initialize(name,absolutepath,absoluteconverterspath,rails_resources_url='')
24
+ def initialize(name,absolutepath,absoluteconverterspath='',rails_resources_url='')
25
25
  @name = name
26
26
  @inpath = absolutepath
27
27
  @converterspath = absoluteconverterspath
@@ -30,6 +30,10 @@ module Publishr
30
30
  @metadata = YAML::load(File.open(File.join(@inpath,'metadata.yml'), 'r').read)
31
31
  end
32
32
 
33
+ def self.gempath
34
+ File.expand_path('../../../', __FILE__)
35
+ end
36
+
33
37
  def make_kindle
34
38
  outpath = File.join(@inpath,'epub')
35
39
  epub = EpubRenderer.new(@name,@inpath,outpath,@metadata, @rails_resources_url)
@@ -70,7 +74,26 @@ module Publishr
70
74
 
71
75
  FileUtils.mv(File.join(outpath,'preamble.pdf'), File.join(@inpath,"#{ @name }.pdf")) if File.exists?(File.join(outpath,'preamble.pdf'))
72
76
  lines.join('<br />')
73
- end
77
+ end
78
+
79
+ def make_images_local(kramdown)
80
+ images = []
81
+ processed_lines = []
82
+ kramdown.split("\n").each do |line|
83
+ match = /\!\[.*?\]\((.*?)\)/.match(line)
84
+ images << match[1] if match
85
+ processed_lines << line.gsub(/\!\[(.*?)\]\((.*?)\)/){ "![#{ $1 }](#{ File.basename($2) })" }
86
+ end
87
+ FileUtils.mkdir_p File.join(@inpath,'images')
88
+ FileUtils.chdir File.join(@inpath,'images')
89
+ output = ["The following files were downloaded into the image folder of your document:\n"]
90
+ images.each do |image|
91
+ FileUtils.rm_f File.join(@inpath,'images',File.basename(image))
92
+ output << `wget -nv #{image} 2>&1`
93
+ end
94
+ return processed_lines.join("\n"), output
95
+ end
96
+
74
97
 
75
98
  end
76
99
  end
@@ -1,3 +1,3 @@
1
1
  module Publishr
2
- VERSION = "0.5.9"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: publishr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-14 00:00:00.000000000Z
12
+ date: 2012-01-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: kramdown
16
- requirement: &16177980 !ruby/object:Gem::Requirement
16
+ requirement: &12817760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *16177980
24
+ version_requirements: *12817760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: kramdown
27
- requirement: &16177320 !ruby/object:Gem::Requirement
27
+ requirement: &12816620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *16177320
35
+ version_requirements: *12816620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sanitize
38
- requirement: &16176880 !ruby/object:Gem::Requirement
38
+ requirement: &12814840 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *16176880
46
+ version_requirements: *12814840
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sanitize
49
- requirement: &16176400 !ruby/object:Gem::Requirement
49
+ requirement: &12813740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *16176400
57
+ version_requirements: *12813740
58
58
  description: Fast publishing for ebooks and paper
59
59
  email:
60
60
  - michael@billgastro.com