knigodej 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +113 -0
- data/Rakefile +59 -0
- data/bin/knigodej +55 -0
- data/knigodej.gemspec +30 -0
- data/lib/knigodej.rb +220 -0
- data/lib/knigodej/version.rb +4 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 19080decf4ce89c56dda65a71a109153af392f55
|
4
|
+
data.tar.gz: 87627dbbff4b614c2f3c6aa3cf7c2e14a90068e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 224f2169d7ebde69ec4100271785bc9bbc2eb9d25813359fc099fa23936c04a02edab7fa20ce71ef8f0f56b7cd699e97e15ac5d9c8f51ab76734e6c625e6875c
|
7
|
+
data.tar.gz: 3df0f16ed32c5b0e5fe93f27c96c53ee628307461fdfb68c4559cdbb2206068af2888e363ad1d71b8115381fca2a2104928480b3e898924688c8893d21018700
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Malo Skrylevo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Knigodej
|
2
|
+
|
3
|
+
Knigodej gem is a tool to make a PDF, and DJVU books from the XCF (GIMP image) source images.
|
4
|
+
Now, only two or many layered XCF images are allowed.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'knigodej', :git => 'git@github.com:3aHyga/knigodej.git'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle install
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install knigodej
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### API
|
23
|
+
|
24
|
+
Here is how to use the Knigodej's API:
|
25
|
+
|
26
|
+
dir = 'books/pdfdjvu'
|
27
|
+
schema = 'books/schema.bs.yml'
|
28
|
+
specbook = 'Specfied Book 1'
|
29
|
+
|
30
|
+
settings = YAML::load( open schema )
|
31
|
+
basepath = File.dirname( schema )
|
32
|
+
bs = BookShelf.new settings, basepath
|
33
|
+
bs.make dir, specbook
|
34
|
+
|
35
|
+
### Scheme
|
36
|
+
|
37
|
+
To build a book thou requirest the book shelf schema file. It is a YAML-config file composed in cyrillic (for now). Sample schema is shewn below:
|
38
|
+
|
39
|
+
---
|
40
|
+
къбукы: path/to/texts
|
41
|
+
наборы:
|
42
|
+
- Scribings 1
|
43
|
+
- Scribings 2
|
44
|
+
главы:
|
45
|
+
1: Chapter 1
|
46
|
+
15: Chapter 2
|
47
|
+
разделы:
|
48
|
+
1: Section 1
|
49
|
+
2: Section 2
|
50
|
+
15: Section 1
|
51
|
+
книги:
|
52
|
+
Specified Book 1:
|
53
|
+
авторы:
|
54
|
+
- Author Name 1
|
55
|
+
- Author Name 2
|
56
|
+
предмет: Subject
|
57
|
+
ключевые слова:
|
58
|
+
- keyword 1
|
59
|
+
- keyword 2
|
60
|
+
создатель: Creator Name
|
61
|
+
страницы:
|
62
|
+
- 1.1.1-4
|
63
|
+
- 1.2.1-3
|
64
|
+
- 2.15.1
|
65
|
+
|
66
|
+
It is applied to file structure that resided itself along the path specified in 'къбукы' parameter: _path/to/texts_. The file structire is shewn below:
|
67
|
+
|
68
|
+
/
|
69
|
+
\Scribings 1
|
70
|
+
\1
|
71
|
+
\1.01. Scribing Page. 0001.xcf
|
72
|
+
\1.01. Scribing Page. 0002.xcf
|
73
|
+
\1.01. Scribing Page. 0003.xcf
|
74
|
+
\1.01. Scribing Page. 0004.xcf
|
75
|
+
\2
|
76
|
+
\1.02. Scribing Page. 0001.xcf
|
77
|
+
\1.02. Scribing Page. 0002.xcf
|
78
|
+
\1.02. Scribing Page. 0003.xcf
|
79
|
+
\Scribings 2
|
80
|
+
\15
|
81
|
+
\
|
82
|
+
\2.15. Scribing Page. 0001.xcf
|
83
|
+
|
84
|
+
The filename in the strcuture consists in follows:
|
85
|
+
|
86
|
+
<chapter index>.<section index>. Page Name. <4 index digits>.xcf
|
87
|
+
|
88
|
+
### Binary
|
89
|
+
|
90
|
+
Here is how to use the Knigodej's binary file. I order to get help issue the following in a command line, and thou wilst get the answer shewn below, which is the help of the knigodej binary:
|
91
|
+
|
92
|
+
$ bin/knigodej -h
|
93
|
+
This is a knigodej script, how to use it see below
|
94
|
+
-v, --verbose 1 enable verbose output, values: 0 to 5
|
95
|
+
-s, --schema set bookshelf schema YAML-file to proceed
|
96
|
+
-b, --book make a book specified by name
|
97
|
+
-d, --dir set base dir to store results
|
98
|
+
-l, --log set output flow to a file
|
99
|
+
-h, --help Show this message
|
100
|
+
-V, --version Print version
|
101
|
+
|
102
|
+
Sample run of the knigodej script with the schema file that is shewn above:
|
103
|
+
|
104
|
+
$ bundle exec bin/knigodej -v 5 -s path/to/book/shelf/newbooks.bs.yml -b "Specific Book 1"
|
105
|
+
|
106
|
+
## Contributing
|
107
|
+
|
108
|
+
1. Fork it
|
109
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
110
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
111
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
112
|
+
5. Create new Pull Request
|
113
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
desc "Prepare bundler"
|
4
|
+
task :bundleup do
|
5
|
+
sh 'gem install bundler --version "~> 1.3.1" --no-ri --no-rdoc'
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Requires"
|
9
|
+
task :req do
|
10
|
+
$: << File.expand_path( '../lib', __FILE__ )
|
11
|
+
require 'bundler/gem_helper'
|
12
|
+
|
13
|
+
Bundler::GemHelper.install_tasks
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Prepare bundle environment"
|
17
|
+
task :up do
|
18
|
+
sh 'bundle install'
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Test with cucumber"
|
22
|
+
task :test do
|
23
|
+
sh 'if [ -d features ]; then tests=$(ls features/*.feature) ; cucumber $tests; fi'
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Distilled clean"
|
27
|
+
task :distclean do
|
28
|
+
sh 'git clean -fd'
|
29
|
+
sh 'cat .gitignore | while read mask; do rm -rf $(find -iname "$mask"); done'
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Generate gem"
|
33
|
+
namespace :gem do
|
34
|
+
task :build => [ :req ] do
|
35
|
+
sh 'gem build knigodej.gemspec'
|
36
|
+
end
|
37
|
+
|
38
|
+
task :install do
|
39
|
+
require File.expand_path( '../lib/knigodej/version', __FILE__ )
|
40
|
+
sh "gem install knigodej-#{Knigodej::VERSION}.gem"
|
41
|
+
end
|
42
|
+
|
43
|
+
task :publish => [ :req ] do
|
44
|
+
require File.expand_path( '../lib/knigodej/version', __FILE__ )
|
45
|
+
sh "git tag v#{Knigodej::VERSION}"
|
46
|
+
sh "gem push knigodej-#{Knigodej::VERSION}.gem"
|
47
|
+
sh "git push"
|
48
|
+
sh "git push --tag"
|
49
|
+
end
|
50
|
+
|
51
|
+
task :make => [ :build, :install, :publish ]
|
52
|
+
task :default => :make
|
53
|
+
end
|
54
|
+
|
55
|
+
task(:default).clear
|
56
|
+
task :default => :test
|
57
|
+
task :all => [ :bundleup, :up, :test, :'gem:make', :distclean ]
|
58
|
+
task :build => [ :bundleup, :up, :test, :'gem:build', :'gem:install', :distclean ]
|
59
|
+
|
data/bin/knigodej
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#coding: utf-8
|
3
|
+
|
4
|
+
require 'rdoba'
|
5
|
+
require 'yaml'
|
6
|
+
require 'micro-optparse'
|
7
|
+
require 'knigodej'
|
8
|
+
|
9
|
+
rdoba :mixin => [ :empty ]
|
10
|
+
|
11
|
+
options = Parser.new do |p|
|
12
|
+
p.banner = "This is a #{Knigodej::NAME} script, how to use it see below"
|
13
|
+
p.version = "#{Knigodej::NAME} #{Knigodej::VERSION}"
|
14
|
+
p.option :verbose, "enable verbose output, values: 0 to 5",
|
15
|
+
:short => 'v', :default => 1, :value_in_set => ( 0..5 ).to_a
|
16
|
+
p.option :schema, "set bookshelf schema YAML-file to proceed",
|
17
|
+
:short => 's', :default => '', :value_matches => /^.+$/
|
18
|
+
p.option :book, "make a book specified by name",
|
19
|
+
:short => 'b', :default => ''
|
20
|
+
p.option :dir, "set base dir to store results", :short => 'd', :default => ''
|
21
|
+
p.option :log, "set output flow to a file", :short => 'l', :default => ''
|
22
|
+
end.process!
|
23
|
+
if !ARGV.empty?
|
24
|
+
$stderr.puts "Invalid option(s): #{ARGV.inspect}" ; exit ; end
|
25
|
+
|
26
|
+
f = case options[ :verbose ]
|
27
|
+
when 0
|
28
|
+
[ :warn ]
|
29
|
+
when 1
|
30
|
+
[ :info, :warn ]
|
31
|
+
when 2
|
32
|
+
[ :info, :warn, :basic ]
|
33
|
+
when 3
|
34
|
+
[ :info, :warn, :basic, :extended ]
|
35
|
+
when 4
|
36
|
+
[ :info, :warn, :basic, :enter, :leave ]
|
37
|
+
when 5
|
38
|
+
[ :info, :warn, :basic, :extended, :enter, :leave ] ; end
|
39
|
+
|
40
|
+
io = ( options[ :log ] == '-' || !options[ :email ].empty? ) &&
|
41
|
+
( require 'tempfile' ; Tempfile.new( 'tmp.log' ) ) ||
|
42
|
+
options[ :log ].empty? && $stdout ||
|
43
|
+
File.open( options[ :log ], 'w+' )
|
44
|
+
|
45
|
+
settings = YAML::load( open options[ :schema ] )
|
46
|
+
|
47
|
+
$stdout.puts "The script is running..."
|
48
|
+
|
49
|
+
rdoba :log => { :in => Knigodej::BookShelf, :as => :log,
|
50
|
+
:prefix => [ :timestamp ], :io => io, :functions => f }
|
51
|
+
rdoba :log => { :in => Knigodej::Book, :as => :log, :prefix => [ :timestamp ],
|
52
|
+
:io => io, :functions => f }
|
53
|
+
|
54
|
+
Knigodej.book settings, options[ :dir ], options[ :book ],
|
55
|
+
File.dirname( options[ :schema ] )
|
data/knigodej.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'knigodej/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "knigodej"
|
8
|
+
spec.version = Knigodej::VERSION
|
9
|
+
spec.authors = ["Malo Skrylevo"]
|
10
|
+
spec.email = ["majioa@yandex.ru"]
|
11
|
+
spec.description = %q{Knigodej gem is a tool to make a PDF, and DJVU books from the XCF (GIMP image) source}
|
12
|
+
spec.summary = %q{Knigodej gem is a tool to make a PDF, and DJVU books from the XCF (GIMP image) source}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'micro-optparse'
|
22
|
+
spec.add_runtime_dependency 'mini_magick', '~> 3.6.0'
|
23
|
+
spec.add_runtime_dependency 'prawn'
|
24
|
+
spec.add_runtime_dependency 'rdoba', '>= 0.9.1'
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
|
29
|
+
spec.requirements << 'djvu-utils'
|
30
|
+
end
|
data/lib/knigodej.rb
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
|
3
|
+
require "knigodej/version"
|
4
|
+
require 'mini_magick'
|
5
|
+
require 'prawn'
|
6
|
+
require 'rdoba'
|
7
|
+
|
8
|
+
module Knigodej
|
9
|
+
rdoba :log => { :functions => :basic }
|
10
|
+
|
11
|
+
class Book
|
12
|
+
rdoba :log => { :functions => :basic }
|
13
|
+
rdoba :mixin => [ :to_h ]
|
14
|
+
|
15
|
+
attr_accessor :authors, :creator, :keywords, :subject
|
16
|
+
|
17
|
+
attr_reader :pages, :name
|
18
|
+
|
19
|
+
def make options = {}
|
20
|
+
log + { options: options }
|
21
|
+
pdffn = options[ :pdf ]
|
22
|
+
djvufn = options[ :djvu ]
|
23
|
+
if !pdffn && !djvufn
|
24
|
+
raise "Neither PDF nor DJVU filename was specified" ; end
|
25
|
+
|
26
|
+
isdjvu = djvufn
|
27
|
+
if `which djvm`.empty?
|
28
|
+
isdjvu = false ; end
|
29
|
+
ispdf = pdffn
|
30
|
+
log > { 'will make PDF?' => !!ispdf, 'will make DJVU?' => !!isdjvu }
|
31
|
+
|
32
|
+
if isdjvu
|
33
|
+
FileUtils.rm_f djvufn ; end
|
34
|
+
|
35
|
+
if ispdf
|
36
|
+
pdf = Prawn::Document.new(
|
37
|
+
:page_size => "A0", #TODO analyze
|
38
|
+
:margin => 0,
|
39
|
+
:info => {
|
40
|
+
:Title => @name,
|
41
|
+
:Author => @authors.join( ',' ),
|
42
|
+
:Subject => @creator,
|
43
|
+
:Keywords => @keywords.join( ',' ),
|
44
|
+
:Creator => @subject,
|
45
|
+
:Producer => "Prawn",
|
46
|
+
:CreationDate => Time.now } )
|
47
|
+
|
48
|
+
pdf.text "Суточный круг богослужения. Знаменный роспев",
|
49
|
+
:size => 18, :align => :center
|
50
|
+
# pdf.bounding_box( [0, pdf.cursor], :width => 2384, :height => 3371 ) do
|
51
|
+
pdf.fill_color "dcd1bf"
|
52
|
+
pdf.fill_polygon [ 0, 0 ], [ 2383, 0 ], [ 2383, 3370 ], [ 0, 3370 ]
|
53
|
+
# end
|
54
|
+
pdf.text "Суточный круг богослужения. Знаменный роспев",
|
55
|
+
:size => 18, :align => :center ; end
|
56
|
+
|
57
|
+
Dir.mktmpdir do |tmpdir|
|
58
|
+
log >> { tmpdir: tmpdir }
|
59
|
+
@pages.each_index do |i|
|
60
|
+
xcf = @pages[ i ]
|
61
|
+
log > { file: xcf }
|
62
|
+
|
63
|
+
# 2512x3552 image size
|
64
|
+
|
65
|
+
tmpfn = File.join tmpdir, 'output.ppm'
|
66
|
+
begin
|
67
|
+
xcf_image = MiniMagick::Image.open xcf
|
68
|
+
bg_image = MiniMagick::Image.new tmpfn
|
69
|
+
|
70
|
+
command = MiniMagick::CommandBuilder.new 'convert -background'
|
71
|
+
command.push 'rgb(221,209,191)' #TODO make it changeable
|
72
|
+
command.push '-flatten'
|
73
|
+
command.push xcf_image.path
|
74
|
+
command.push bg_image.path
|
75
|
+
bg_image.run command
|
76
|
+
|
77
|
+
if isdjvu
|
78
|
+
outfn = File.join tmpdir, 'output.djvu'
|
79
|
+
`cpaldjvu -dpi 150 -colors 4 '#{tmpfn}' '#{outfn}'`
|
80
|
+
if File.exist?( djvufn )
|
81
|
+
`djvm -c '#{djvufn}' '#{djvufn}' '#{outfn}'`
|
82
|
+
else
|
83
|
+
p `djvm -c '#{djvufn}' '#{outfn}'` ; end ; end
|
84
|
+
|
85
|
+
if ispdf
|
86
|
+
# Generating the PDF
|
87
|
+
tmp_image = MiniMagick::Image.open tmpfn
|
88
|
+
pngfn = File.join tmpdir, 'output.png'
|
89
|
+
png_image = MiniMagick::Image.new pngfn
|
90
|
+
|
91
|
+
command = MiniMagick::CommandBuilder.new 'convert'
|
92
|
+
command.push tmp_image.path
|
93
|
+
command.push png_image.path
|
94
|
+
tmp_image.run command
|
95
|
+
|
96
|
+
# "A0" => [2383.94, 3370.39],
|
97
|
+
pdf.start_new_page
|
98
|
+
pdf.bounding_box( [0, pdf.cursor], :width => 2384, :height => 3371 ) do
|
99
|
+
pdf.image pngfn, :fit => [2384, 3371] #TODO hardcoded remove
|
100
|
+
end ; end
|
101
|
+
|
102
|
+
# FileUtils.rm_f [ tmpfn, pngfn ]
|
103
|
+
rescue
|
104
|
+
log.e ; end ; end
|
105
|
+
|
106
|
+
pdf.render_file pdffn ; end
|
107
|
+
|
108
|
+
=begin
|
109
|
+
outline.define do
|
110
|
+
section("Section 1", :destination => 1) do
|
111
|
+
page :title => "Page 2", :destination => 2
|
112
|
+
page :title => "Page 3", :destination => 3
|
113
|
+
end
|
114
|
+
section("Section 2", :destination => 4) do
|
115
|
+
page :title => "Page 5", :destination => 5
|
116
|
+
section("Subsection 2.1", :destination => 6, :closed => true) do
|
117
|
+
page :title => "Page 7", :destination => 7
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
=end
|
122
|
+
log - {} ; end
|
123
|
+
|
124
|
+
|
125
|
+
def initialize name, b, path, sets
|
126
|
+
log + { b: b, path: path, sets: sets }
|
127
|
+
|
128
|
+
@pages = []
|
129
|
+
if b.empty? || name.empty?
|
130
|
+
return ; end
|
131
|
+
|
132
|
+
@name = name
|
133
|
+
@authors = b[ 'авторы' ]
|
134
|
+
@creator = b[ 'создатель' ]
|
135
|
+
@keywords = b[ 'ключевые слова' ]
|
136
|
+
@subject = b[ 'предмет' ]
|
137
|
+
|
138
|
+
(set, chapter, section) = [ nil, nil, nil ]
|
139
|
+
b[ 'страницы' ].each do |page|
|
140
|
+
# b[ 'страницы' ].пере(еже) do |page| TODO
|
141
|
+
log > { page: page }
|
142
|
+
if page =~ /(.*)\.(.*)\.(.*)\.(.*)/
|
143
|
+
( set, chapter, glas, section ) = [ $1.to_i - 1, $2.to_i, $3, $4 ]
|
144
|
+
elsif page =~ /(.*)\.(.*)\.(.*)/
|
145
|
+
( set, chapter, glas, section ) = [ $1.to_i - 1, $2.to_i, nil, $3 ]
|
146
|
+
elsif page =~ /(.*)\.(.*)/
|
147
|
+
( set, chapter, glas, section ) = [ $1.to_i - 1, nil, nil, $2 ]; end
|
148
|
+
if !set
|
149
|
+
next; end
|
150
|
+
|
151
|
+
# dir = "./share/букы/#{s[ 'наборы' ][ set ]}/#{chapter}/"
|
152
|
+
dir = File.join path, sets[ set ].to_s, chapter.to_s
|
153
|
+
log > { dir: dir }
|
154
|
+
|
155
|
+
clist = begin
|
156
|
+
Dir.foreach( dir ).sort.map do |file|
|
157
|
+
if file =~ /(?:(\d)\. )?(\d?\d\d\d)\.xcf$/
|
158
|
+
[ [ $1, $2.to_i ], [ $1, file ] ]
|
159
|
+
end
|
160
|
+
end.compact.to_h
|
161
|
+
rescue Errno::ENOENT
|
162
|
+
log.e
|
163
|
+
{}
|
164
|
+
end
|
165
|
+
log >> { 'temporary list: ' => clist }
|
166
|
+
|
167
|
+
section.split( /,/ ).each do |sec|
|
168
|
+
if sec =~ /(\d+)-(\d+)/
|
169
|
+
($1.to_i..$2.to_i).each do |i|
|
170
|
+
begin
|
171
|
+
if clist[ [ glas, i ] ]
|
172
|
+
@pages << File.join( dir, clist[ [ glas, i ] ][ 1 ] ) ; end
|
173
|
+
rescue
|
174
|
+
log.e
|
175
|
+
end
|
176
|
+
end
|
177
|
+
elsif sec =~ /(\d+)/
|
178
|
+
begin
|
179
|
+
if clist[ [ glas, $1.to_i ] ]
|
180
|
+
@pages << File.join( dir, clist[ [ glas, $1.to_i ] ][ 1 ] ) ; end
|
181
|
+
rescue
|
182
|
+
log.e ; end ; end ; end ; end
|
183
|
+
log >> { 'Book pages' => @pages } ; end ; end
|
184
|
+
|
185
|
+
class BookShelf
|
186
|
+
rdoba :log => { :functions => :basic }
|
187
|
+
|
188
|
+
attr_reader :books
|
189
|
+
|
190
|
+
def make dir, specbook = nil
|
191
|
+
log + { dir: dir, specbook: specbook }
|
192
|
+
|
193
|
+
books = specbook && @books.select {|b| b.name == specbook } || @books
|
194
|
+
if dir.empty?
|
195
|
+
dir = './' ; end
|
196
|
+
books.each do |book|
|
197
|
+
log >> { book: book }
|
198
|
+
pdffn = File.join dir, "#{book.name}.pdf"
|
199
|
+
djvufn = File.join dir, "#{book.name}.djvu"
|
200
|
+
book.make :pdf => pdffn, :djvu => djvufn ; end ; end
|
201
|
+
|
202
|
+
def initialize s, basepath = './'
|
203
|
+
log + { s: s }
|
204
|
+
@books = []
|
205
|
+
s[ 'книги' ].each_pair do |book, value|
|
206
|
+
log > { book: book, value: value }
|
207
|
+
if value.empty?
|
208
|
+
next ; end
|
209
|
+
path = s[ 'къбукы' ] =~ /^[\/~]/ && s[ 'къбукы' ] ||
|
210
|
+
File.join( basepath, s[ 'къбукы' ] )
|
211
|
+
sets = s[ 'наборы' ]
|
212
|
+
@books << Book.new( book, value, path, sets ) ; end
|
213
|
+
log >> { :@books => @books } ; end ; end
|
214
|
+
|
215
|
+
def self.book settings, dir, specbook = nil, basepath = './'
|
216
|
+
# log + { settings: settings } TODO
|
217
|
+
bs = BookShelf.new settings, basepath
|
218
|
+
bs.make dir, specbook
|
219
|
+
end ; end
|
220
|
+
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knigodej
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Malo Skrylevo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2013-10-01 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: micro-optparse
|
16
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- &id003
|
19
|
+
- ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: "0"
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *id001
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mini_magick
|
27
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 3.6.0
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id002
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: prawn
|
37
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- *id003
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: *id004
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rdoba
|
45
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.9.1
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: *id005
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: bundler
|
55
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "1.3"
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: *id006
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rake
|
65
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- *id003
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id007
|
71
|
+
description: Knigodej gem is a tool to make a PDF, and DJVU books from the XCF (GIMP image) source
|
72
|
+
email:
|
73
|
+
- majioa@yandex.ru
|
74
|
+
executables:
|
75
|
+
- knigodej
|
76
|
+
extensions: []
|
77
|
+
|
78
|
+
extra_rdoc_files: []
|
79
|
+
|
80
|
+
files:
|
81
|
+
- .gitignore
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/knigodej
|
87
|
+
- knigodej.gemspec
|
88
|
+
- lib/knigodej.rb
|
89
|
+
- lib/knigodej/version.rb
|
90
|
+
homepage: ""
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- *id003
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- *id003
|
106
|
+
requirements:
|
107
|
+
- djvu-utils
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.1.4
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Knigodej gem is a tool to make a PDF, and DJVU books from the XCF (GIMP image) source
|
113
|
+
test_files: []
|
114
|
+
|