epubforge 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +17 -10
- data/VERSION +1 -1
- data/bin/epubforge +1 -1
- data/config/actions/epub.rb +50 -0
- data/config/actions/forge.rb +34 -13
- data/config/actions/git.rb +106 -0
- data/config/actions/help.rb +13 -13
- data/config/actions/html.rb +33 -0
- data/config/actions/mobi.rb +60 -0
- data/config/actions/new.rb +182 -0
- data/config/actions/word_count.rb +26 -24
- data/config/{actions → actions_to_ignore}/generate.rb +1 -1
- data/config/{actions → actions_to_ignore}/generate_chapter.rb +0 -0
- data/config/{actions → actions_to_ignore}/git_backup.rb +2 -2
- data/config/{actions → actions_to_ignore}/globals.rb +1 -1
- data/config/{actions → actions_to_ignore}/kindle.rb +3 -3
- data/config/{actions → actions_to_ignore}/local_action.rb +1 -1
- data/config/{actions → actions_to_ignore}/mobify.rb +3 -3
- data/config/actions_to_ignore/notes_to_epub.rb +19 -0
- data/config/actions_to_ignore/notes_to_kindle.rb +18 -0
- data/config/{actions → actions_to_ignore}/spell.rb +1 -1
- data/config/{actions → actions_to_ignore}/version.rb +3 -3
- data/config/{actions → actions_to_ignore}/wrap_scene_notes_in_hidden_div.rb +1 -1
- data/config/converters/epub_to_mobi.calibre.rb +8 -0
- data/config/converters/epub_to_mobi.kindlegen.rb +11 -0
- data/config/html_translators/default_kramdown.html_translator.rb +9 -0
- data/config/html_translators/default_markdown.html_translator.rb +10 -0
- data/config/html_translators/default_markdown_pandoc.html_translator.rb +10 -0
- data/config/html_translators/default_textile_pandoc.html_translator.rb +8 -0
- data/config/html_translators/default_xhtml.html_translator.rb +7 -0
- data/config/html_translators/fallback_html.html_translator.rb +9 -0
- data/config/html_translators/fallback_markdown.html_translator.rb +8 -0
- data/config/html_translators/fallback_textile.html_translator.rb +7 -0
- data/config/html_translators/fallback_txt.html_translator.rb +8 -0
- data/config/html_translators/fallback_unknown.html_translator.rb +7 -0
- data/lib/epubforge.rb +37 -82
- data/lib/{action/thor_action.rb → epubforge/action/action.rb} +89 -69
- data/lib/epubforge/action/action2.rb +109 -0
- data/lib/epubforge/action/action_definition.rb +62 -0
- data/lib/epubforge/action/actions_lookup.rb +45 -0
- data/lib/epubforge/action/chatterbox.rb +93 -0
- data/lib/{action → epubforge/action}/cli_command.rb +2 -2
- data/lib/{action → epubforge/action}/cli_sequence.rb +0 -0
- data/lib/{action → epubforge/action}/file_transformer.rb +0 -0
- data/lib/{action → epubforge/action}/hooks_interface.rb +2 -2
- data/lib/{action → epubforge/action}/run_description.rb +12 -9
- data/lib/{action → epubforge/action}/runner.rb +23 -24
- data/lib/{epub → epubforge/builder}/assets/asset.rb +1 -1
- data/lib/{epub → epubforge/builder}/assets/font.rb +1 -1
- data/lib/epubforge/builder/assets/html.rb +9 -0
- data/lib/{epub → epubforge/builder}/assets/image.rb +1 -1
- data/lib/epubforge/builder/assets/markdown.rb +9 -0
- data/lib/{epub → epubforge/builder}/assets/page.rb +12 -4
- data/lib/{epub → epubforge/builder}/assets/stylesheet.rb +1 -1
- data/lib/epubforge/builder/assets/textile.rb +9 -0
- data/lib/epubforge/builder/assets/xhtml.rb +9 -0
- data/lib/epubforge/builder/builder.rb +134 -0
- data/lib/{epub/builder.rb → epubforge/builder/epub.rb} +58 -161
- data/lib/epubforge/builder/html.rb +22 -0
- data/lib/epubforge/builder/packager.rb +16 -0
- data/lib/epubforge/core_extensions/array.rb +2 -0
- data/lib/{core_extensions → epubforge/core_extensions}/kernel.rb +0 -0
- data/lib/epubforge/core_extensions/nil_class.rb +2 -0
- data/lib/epubforge/core_extensions/object.rb +24 -0
- data/lib/{core_extensions → epubforge/core_extensions}/string.rb +1 -5
- data/lib/{custom_helpers.rb → epubforge/custom_helpers.rb} +0 -1
- data/lib/{errors.rb → epubforge/exceptions/errors.rb} +0 -0
- data/lib/{project → epubforge/project}/project.rb +23 -17
- data/lib/epubforge/utils/action_loader.rb +8 -0
- data/lib/epubforge/utils/class_loader.rb +102 -0
- data/lib/epubforge/utils/converter.rb +94 -0
- data/lib/{utils → epubforge/utils}/downloader.rb +0 -0
- data/lib/{utils → epubforge/utils}/file_orderer.rb +0 -0
- data/lib/epubforge/utils/file_path.rb +8 -0
- data/lib/epubforge/utils/html_translator.rb +126 -0
- data/lib/epubforge/utils/html_translator_queue.rb +113 -0
- data/lib/epubforge/utils/htmlizer.rb +61 -0
- data/lib/{utils → epubforge/utils}/misc.rb +0 -0
- data/lib/epubforge/utils/root_path.rb +8 -0
- data/lib/epubforge/utils/settings.rb +147 -0
- data/lib/epubforge/utils/template_evaluator.rb +7 -0
- data/templates/{default/book/afterword.markdown.template → project/book/afterword.markdown} +0 -0
- data/templates/project/book/chapter-%0000chapter%.markdown.template +4 -0
- data/templates/{default → project}/book/cover.xhtml.template +2 -2
- data/templates/{default/book/foreword.markdown.template → project/book/foreword.markdown} +0 -0
- data/templates/{default → project}/book/images/cover.png +0 -0
- data/templates/{default/book/stylesheets/stylesheet.css.template → project/book/stylesheets/stylesheet.css} +0 -0
- data/templates/project/book/title_page.markdown.template +5 -0
- data/templates/project/notes/character.%character.name_for_file%.markdown.template +15 -0
- data/templates/{default → project}/notes/images/cover.png +0 -0
- data/templates/{default/notes/stylesheets/stylesheet.css.template → project/notes/stylesheets/stylesheet.css} +0 -0
- data/templates/{default → project}/settings/actions/local_action.rb.example +1 -1
- data/templates/project/settings/config.rb.template +70 -0
- data/templates/project/settings/html_translators/example_translator.rb +29 -0
- data/templates/{default → project}/settings/wordcount.template +1 -1
- data/test/answers01.yml +30 -0
- data/test/helper.rb +62 -39
- data/test/misc/config.rb +5 -7
- data/test/test_epubforge.rb +18 -14
- data/test/{test_htmlizers.rb → test_html_translators.rb} +4 -8
- data/test/test_template_evaluator.rb +42 -0
- data/test/test_utils.rb +0 -11
- metadata +186 -189
- data/config/actions/gitify.rb +0 -72
- data/config/actions/init.rb +0 -138
- data/config/actions/notes_to_epub.rb +0 -18
- data/config/actions/notes_to_kindle.rb +0 -17
- data/config/htmlizers.rb +0 -70
- data/lib/action/actions_lookup.rb +0 -45
- data/lib/core_extensions/array.rb +0 -5
- data/lib/core_extensions/nil_class.rb +0 -5
- data/lib/core_extensions/object.rb +0 -5
- data/lib/epub/assets/html.rb +0 -8
- data/lib/epub/assets/markdown.rb +0 -8
- data/lib/epub/assets/textile.rb +0 -8
- data/lib/epub/assets/xhtml.rb +0 -8
- data/lib/epub/packager.rb +0 -16
- data/lib/utils/action_loader.rb +0 -7
- data/lib/utils/class_loader.rb +0 -102
- data/lib/utils/directory_builder.rb +0 -181
- data/lib/utils/file_path.rb +0 -152
- data/lib/utils/html_translator.rb +0 -100
- data/lib/utils/html_translator_queue.rb +0 -70
- data/lib/utils/htmlizer.rb +0 -92
- data/lib/utils/root_path.rb +0 -20
- data/lib/utils/settings.rb +0 -146
- data/lib/utils/template_evaluator.rb +0 -20
- data/templates/default/book/chapter-%i%.markdown.sequence +0 -4
- data/templates/default/book/title_page.markdown.template +0 -4
- data/templates/default/notes/character.named.markdown.template +0 -4
- data/templates/default/payload.rb +0 -65
- data/templates/default/settings/config.rb.form +0 -55
- data/templates/default/settings/htmlizers.rb +0 -0
- data/test/test_directory_builder.rb +0 -141
data/lib/utils/action_loader.rb
DELETED
data/lib/utils/class_loader.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
module EpubForge
|
2
|
-
module Utils
|
3
|
-
# filepath string with metadata, representing a class
|
4
|
-
# file that can be loaded.
|
5
|
-
class ClassLoader < FunWith::Files::FilePath
|
6
|
-
def self.loaded_classes
|
7
|
-
@loaded_classes ||= []
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.loaded_directories
|
11
|
-
@loaded_directories ||= []
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.namespace( nsp = nil )
|
15
|
-
@namespace = nsp unless nsp.nil?
|
16
|
-
@namespace
|
17
|
-
end
|
18
|
-
|
19
|
-
def class_name
|
20
|
-
unless @class_name
|
21
|
-
base = self.basename.to_s.split(".")[0].epf_camelize
|
22
|
-
@class_name = "#{self.class.namespace}::#{base}"
|
23
|
-
end
|
24
|
-
@class_name
|
25
|
-
end
|
26
|
-
|
27
|
-
# Returns true if an error was raised when trying to require the file,
|
28
|
-
# or if the expected class is not loaded after the file was required.
|
29
|
-
# Proper naming is very important here.
|
30
|
-
def require_me
|
31
|
-
begin
|
32
|
-
require self.to_s
|
33
|
-
rescue NameError => e
|
34
|
-
puts "Error encounterd while trying to load #{self.class_name} from #{self}"
|
35
|
-
puts e.message
|
36
|
-
puts e.backtrace.map{|line| "\t#{line}" }
|
37
|
-
return false
|
38
|
-
end
|
39
|
-
|
40
|
-
return self.class_loaded?
|
41
|
-
end
|
42
|
-
|
43
|
-
def class_loaded?
|
44
|
-
begin
|
45
|
-
self.to_class
|
46
|
-
return true
|
47
|
-
rescue NameError # There's gotta be another way I should be doing this.
|
48
|
-
return false
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def to_class
|
53
|
-
return @klass unless @klass.nil?
|
54
|
-
@klass = Utils::Misc.constantize( self.class_name )
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.require_me( *loadables )
|
58
|
-
@loaded_classes ||= []
|
59
|
-
@loaded_directories ||= []
|
60
|
-
|
61
|
-
for loadable in loadables
|
62
|
-
loadable = self.new( loadable )
|
63
|
-
|
64
|
-
if loadable.file?
|
65
|
-
if loadable.require_me
|
66
|
-
@loaded_classes << loadable.to_class
|
67
|
-
else
|
68
|
-
puts "Warning: Failed to load #{loadable.class_name} from file #{loadable}"
|
69
|
-
end
|
70
|
-
elsif loadable.directory?
|
71
|
-
@loaded_directories << loadable
|
72
|
-
loadable.glob( "**", "*.rb" ).each do |entry|
|
73
|
-
self.require_me( entry )
|
74
|
-
end
|
75
|
-
else
|
76
|
-
puts "Warning: Could not find file #{loadable} to load classes from."
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# just loading all the files is simpler, and probably little harm from reloading. Plus, I want
|
82
|
-
# to be able to split up existing ThorClasses across multiple files.
|
83
|
-
def self.load_me( *loadables )
|
84
|
-
silence_warnings do
|
85
|
-
for loadable in loadables
|
86
|
-
loadable = loadable.fwf_filepath
|
87
|
-
|
88
|
-
if loadable.file?
|
89
|
-
load( loadable )
|
90
|
-
elsif loadable.directory?
|
91
|
-
for entry in loadable.glob( :ext => "rb", :recursive => true )
|
92
|
-
load( entry )
|
93
|
-
end
|
94
|
-
else
|
95
|
-
puts "Warning: No idea what I'm trying to load (#{loadable}:#{loadable.class})"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,181 +0,0 @@
|
|
1
|
-
module EpubForge
|
2
|
-
module Utils
|
3
|
-
class DirectoryBuilder
|
4
|
-
attr_accessor :current_path, :current_file
|
5
|
-
|
6
|
-
def initialize( path )
|
7
|
-
@paths = []
|
8
|
-
@current_path = path.fwf_filepath
|
9
|
-
make_path
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.create( path, &block )
|
13
|
-
builder = self.new( path )
|
14
|
-
yield builder if block_given?
|
15
|
-
builder
|
16
|
-
end
|
17
|
-
|
18
|
-
def dir( *args, &block )
|
19
|
-
descend( *args ) do
|
20
|
-
yield if block_given?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# block must be given
|
25
|
-
def self.tmpdir( &block )
|
26
|
-
if block_given?
|
27
|
-
Dir.mktmpdir do |dir|
|
28
|
-
self.create( dir ) do |builder|
|
29
|
-
yield builder
|
30
|
-
end
|
31
|
-
end
|
32
|
-
else
|
33
|
-
self.create( Dir.mktmpdir )
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
# Copies the given source file into a file in the current_path.
|
38
|
-
# If a dest_name is given, the new file will be given that name.
|
39
|
-
def copy( src_filepath, dst_name = nil )
|
40
|
-
dst_filepath = dst_name ? @current_path.join( dst_name ) : @current_path
|
41
|
-
FileUtils.copy( src_filepath, dst_filepath )
|
42
|
-
end
|
43
|
-
|
44
|
-
def file( name = nil, content = nil, &block )
|
45
|
-
# if name && content
|
46
|
-
# begin
|
47
|
-
# f = open_file( name )
|
48
|
-
# f << content
|
49
|
-
# ensure
|
50
|
-
# close_file
|
51
|
-
# end
|
52
|
-
if name
|
53
|
-
open_file( name )
|
54
|
-
@current_file << content if content
|
55
|
-
if block_given?
|
56
|
-
begin
|
57
|
-
yield @current_file
|
58
|
-
ensure
|
59
|
-
close_file
|
60
|
-
end
|
61
|
-
end
|
62
|
-
else
|
63
|
-
@current_file
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def current_file
|
68
|
-
@current_file ? FunWith::Files::FilePath.new( @current_file.path ) : nil
|
69
|
-
end
|
70
|
-
|
71
|
-
# if file not given, the result is appended to the current file.
|
72
|
-
def download( url, file = nil )
|
73
|
-
if file
|
74
|
-
if file.fwf_filepath.relative?
|
75
|
-
file = FunWith::Files::FilePath.new( @current_path, file )
|
76
|
-
end
|
77
|
-
|
78
|
-
File.open( file, "w" ) do |f|
|
79
|
-
download_to_target( url, f )
|
80
|
-
end
|
81
|
-
elsif @current_file
|
82
|
-
download_to_target( url, @current_file )
|
83
|
-
else
|
84
|
-
puts "No current file to append #{url} to."
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def template( src, dst, vars = {} )
|
89
|
-
self.file( dst ) do |f|
|
90
|
-
f << Utils::TemplateEvaluator.new( src, vars ).result
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
protected
|
95
|
-
def make_path
|
96
|
-
FileUtils.mkdir_p( @current_path ) unless @current_path.exist?
|
97
|
-
end
|
98
|
-
|
99
|
-
def descend( *args, &block )
|
100
|
-
if @current_path.directory?
|
101
|
-
close_file
|
102
|
-
@paths << @current_path
|
103
|
-
@current_path = @paths.last.join( *args )
|
104
|
-
make_path
|
105
|
-
yield
|
106
|
-
@current_path = @paths.pop
|
107
|
-
close_file
|
108
|
-
else
|
109
|
-
raise "Cannot descend."
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def open_file( name )
|
114
|
-
close_file
|
115
|
-
@current_file = File.open( @current_path.join( name ), "w" )
|
116
|
-
end
|
117
|
-
|
118
|
-
def close_file
|
119
|
-
if @current_file
|
120
|
-
@current_file.flush
|
121
|
-
@current_file.close
|
122
|
-
end
|
123
|
-
|
124
|
-
@current_file = nil
|
125
|
-
end
|
126
|
-
|
127
|
-
def download_to_target( url, file )
|
128
|
-
Downloader.new.download( url, file )
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
|
135
|
-
# sample code
|
136
|
-
#
|
137
|
-
# DirBuilder.create( '~/project' ) do |b| # starts by creating directory. If parent
|
138
|
-
# # directories don't exist, they will soon.
|
139
|
-
# # if you use DirBuilder.tmp('~/project'), a tempdir
|
140
|
-
# # is created, and its contents relocated to ~/project when the
|
141
|
-
# # block terminates.
|
142
|
-
# b.dir("images") do # creates subdirectory "images"
|
143
|
-
# for img in src_dir.entries.select{|img| img.extension == ".png"}
|
144
|
-
# b.copy( src_dir.join( img.filename ) ) # copies a bunch of files from another directory
|
145
|
-
# end # rises back to the initial '~/project directory
|
146
|
-
#
|
147
|
-
# b.copy( src_dir.join( "rorshach.xml" ) )
|
148
|
-
# b.download( "dest.bash", "http://get.rvm.io" ) # downloads file directly beneath '~/project'
|
149
|
-
# # maybe someday, though
|
150
|
-
#
|
151
|
-
# b.dir("text", "scenes") do # creates ~/project/text/scenes subdir
|
152
|
-
# b.file( "adventure_time.txt" ) do |f|
|
153
|
-
# f << "Fill this in later"
|
154
|
-
# end
|
155
|
-
#
|
156
|
-
# # calling .file without feeding it a block leaves it open for writing,
|
157
|
-
# # until either the enclosing block terminates or .file is called
|
158
|
-
# # again with a string argument.
|
159
|
-
# b.file( "another_brick.txt" )
|
160
|
-
# b.file << "Hey, you!"
|
161
|
-
# b.file << "Yes, you!"
|
162
|
-
# b.file.push "Stand still, laddie!"
|
163
|
-
#
|
164
|
-
# b.template(templates_dir.join("blue_template.txt")) do |t|
|
165
|
-
# t.var(:fname, "John")
|
166
|
-
# t.var(:lname, "Macey")
|
167
|
-
# t.var(:state, "Ohio")
|
168
|
-
# t.vars(graduated: "2003")
|
169
|
-
# t.vars(quot: "That wasn't my duck.", photo: "john.png", css: "font-family: arial")
|
170
|
-
# end
|
171
|
-
#
|
172
|
-
# b.copy( [src_dir.join("abba.txt"), "baab.txt"] ) # contents of abba.txt copied into baab.txt
|
173
|
-
#
|
174
|
-
#
|
175
|
-
# b.file( ".lockfile" ) # creates an empty file
|
176
|
-
# end
|
177
|
-
#
|
178
|
-
# b.
|
179
|
-
# end
|
180
|
-
#
|
181
|
-
|
data/lib/utils/file_path.rb
DELETED
@@ -1,152 +0,0 @@
|
|
1
|
-
module EpubForge
|
2
|
-
module Utils
|
3
|
-
class FilePath < Pathname
|
4
|
-
def initialize( *args )
|
5
|
-
super( File.join( *args ) )
|
6
|
-
end
|
7
|
-
|
8
|
-
# args implicitly joined to cwd
|
9
|
-
def self.cwd( *args )
|
10
|
-
Dir.pwd.fwf_filepath.join( *args )
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.pwd( *args )
|
14
|
-
self.cwd( *args )
|
15
|
-
end
|
16
|
-
|
17
|
-
def join( *args, &block )
|
18
|
-
if block_given?
|
19
|
-
yield self.class.new( super(*args) )
|
20
|
-
else
|
21
|
-
self.class.new( super(*args) )
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
alias :exists? :exist?
|
26
|
-
|
27
|
-
def up
|
28
|
-
self.class.new( self.join("..") ).expand
|
29
|
-
end
|
30
|
-
|
31
|
-
# opts:
|
32
|
-
# :class => [self.class] The class of objects you want returned (String, FilePath, ClassLoader, etc.)
|
33
|
-
# Should probably be a subclass of FilePath or String. Class.init must accept a string
|
34
|
-
# [representing a file path] as the sole argument.
|
35
|
-
#
|
36
|
-
# :recurse => [false]
|
37
|
-
# :ext => [] A single symbol, or a list containing strings/symbols representing file name extensions.
|
38
|
-
# No leading periods kthxbai.
|
39
|
-
#
|
40
|
-
# If opts not given, the user can still do it explicitly with arguments like .glob("**", "*.rb")
|
41
|
-
def glob( *args )
|
42
|
-
opts = args.last.is_a?(Hash) ? args.pop : {}
|
43
|
-
|
44
|
-
recurser = opts[:recurse] ? "**" : nil
|
45
|
-
extensions = case opts[:ext]
|
46
|
-
when Symbol, String
|
47
|
-
"*.#{opts[:ext]}"
|
48
|
-
when Array
|
49
|
-
extensions = opts[:ext].map(&:to_s).join(',')
|
50
|
-
"*.{#{extensions}}"
|
51
|
-
when NilClass
|
52
|
-
nil
|
53
|
-
end
|
54
|
-
|
55
|
-
args += [recurser, extensions]
|
56
|
-
args.compact!
|
57
|
-
|
58
|
-
opts[:class] ||= self.class
|
59
|
-
Dir.glob( self.join(*args) ).map{ |f| opts[:class].new(f) }
|
60
|
-
end
|
61
|
-
|
62
|
-
def expand
|
63
|
-
self.class.new( File.expand_path( self ) )
|
64
|
-
end
|
65
|
-
|
66
|
-
def touch
|
67
|
-
FileUtils.touch( self )
|
68
|
-
return true
|
69
|
-
rescue Errno::EACCESS
|
70
|
-
return false
|
71
|
-
end
|
72
|
-
|
73
|
-
def touch_dir
|
74
|
-
FileUtils.mkdir_p( self )
|
75
|
-
return true
|
76
|
-
rescue Errno::EEXIST
|
77
|
-
return true
|
78
|
-
rescue Errno::EACCESS
|
79
|
-
return false
|
80
|
-
end
|
81
|
-
|
82
|
-
def write( content = nil, &block )
|
83
|
-
File.open( self, "w" ) do |f|
|
84
|
-
f << content if content
|
85
|
-
if block_given?
|
86
|
-
yield f
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def append( content = nil, &block )
|
92
|
-
File.open( self, "a" ) do |f|
|
93
|
-
f << content if content
|
94
|
-
if block_given?
|
95
|
-
yield f
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def grep( regex )
|
101
|
-
return [] unless self.file?
|
102
|
-
matching = []
|
103
|
-
self.each_line do |line|
|
104
|
-
matching.push( line ) if line.match( regex )
|
105
|
-
end
|
106
|
-
matching
|
107
|
-
end
|
108
|
-
|
109
|
-
# Not the same as zero?
|
110
|
-
def empty?
|
111
|
-
raise Exceptions::FileDoesNotExist unless self.exist?
|
112
|
-
|
113
|
-
if self.file?
|
114
|
-
File.size( self ) == 0
|
115
|
-
elsif self.directory?
|
116
|
-
self.glob( "**", "*" ).length == 0
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def basename_no_ext
|
121
|
-
self.basename.to_s.split(".")[0..-2].join(".").fwf_filepath
|
122
|
-
end
|
123
|
-
|
124
|
-
def without_ext
|
125
|
-
self.gsub(/\.#{self.ext}$/, '')
|
126
|
-
end
|
127
|
-
|
128
|
-
def ext
|
129
|
-
self.basename.to_s.split(".").last || ""
|
130
|
-
end
|
131
|
-
|
132
|
-
def relative_path_from( ancestor_dir )
|
133
|
-
depth = ancestor_dir.to_s.split(File::SEPARATOR).length
|
134
|
-
relative_path = self.to_s.split(File::SEPARATOR)
|
135
|
-
relative_path[(depth)..-1].join(File::SEPARATOR).fwf_filepath
|
136
|
-
end
|
137
|
-
|
138
|
-
def gsub( *args )
|
139
|
-
self.to_s.gsub(*args).fwf_filepath
|
140
|
-
end
|
141
|
-
|
142
|
-
def gsub!( *args )
|
143
|
-
new_str = self.to_s.gsub(*args)
|
144
|
-
self.instance_variable_set(:@path, new_str)
|
145
|
-
end
|
146
|
-
|
147
|
-
def fwf_filepath
|
148
|
-
self
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
module EpubForge
|
2
|
-
module Utils
|
3
|
-
# An individual translator, which receives a filename, determines if it's up to the job
|
4
|
-
# then returns the resulting HTML translation.
|
5
|
-
class HtmlTranslator
|
6
|
-
GROUP_NAMES = [:preferred, :user, :default, :fallback]
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
group( :user )
|
10
|
-
opts( "" )
|
11
|
-
end
|
12
|
-
|
13
|
-
def name( n = nil )
|
14
|
-
@name = n if n
|
15
|
-
@name
|
16
|
-
end
|
17
|
-
|
18
|
-
def group( g = nil )
|
19
|
-
if g
|
20
|
-
raise "group must be one of the following symbols: #{GROUP_NAMES.inspect}" unless GROUP_NAMES.include?(g)
|
21
|
-
@group = g
|
22
|
-
end
|
23
|
-
|
24
|
-
@group
|
25
|
-
end
|
26
|
-
|
27
|
-
def executable executable_name = nil
|
28
|
-
if executable_name
|
29
|
-
@executable_name = Htmlizer.instance.location( executable_name ) || `which #{executable_name}`.strip
|
30
|
-
end
|
31
|
-
@executable_name || ""
|
32
|
-
end
|
33
|
-
|
34
|
-
def format f = nil
|
35
|
-
@format = f if f
|
36
|
-
@format
|
37
|
-
end
|
38
|
-
|
39
|
-
def cmd c = nil
|
40
|
-
@cmd = c if c
|
41
|
-
@cmd
|
42
|
-
end
|
43
|
-
|
44
|
-
def custom_proc( p = nil, &block )
|
45
|
-
if block_given?
|
46
|
-
@custom_proc = block
|
47
|
-
else
|
48
|
-
@custom_proc = c if c
|
49
|
-
end
|
50
|
-
|
51
|
-
@custom_proc
|
52
|
-
end
|
53
|
-
|
54
|
-
def opts o = nil
|
55
|
-
@opts = o if o
|
56
|
-
@opts
|
57
|
-
end
|
58
|
-
|
59
|
-
def installed?
|
60
|
-
executable.length > 0
|
61
|
-
end
|
62
|
-
|
63
|
-
def handles_format?( f )
|
64
|
-
@format == determine_file_format( f ) || @format == :unknown
|
65
|
-
end
|
66
|
-
|
67
|
-
def can_do_job?( f )
|
68
|
-
installed? && handles_format?( f )
|
69
|
-
end
|
70
|
-
|
71
|
-
# opts allows you to override the normal command line arguments
|
72
|
-
# Maybe a description of the job's requirements should be more
|
73
|
-
# elaborate than just a filename. OTOH, simple can have its advantages.
|
74
|
-
def translate( filename, opts = "" )
|
75
|
-
return false unless can_do_job?( filename )
|
76
|
-
|
77
|
-
result = ""
|
78
|
-
if @custom_proc
|
79
|
-
result += @custom_proc.call( filename, *opts )
|
80
|
-
elsif @cmd
|
81
|
-
exec_string = cmd.gsub( /\{\{f\}\}/, filename.to_s )
|
82
|
-
opts = @opts if opts.epf_blank?
|
83
|
-
exec_string.gsub!( /\{\{o\}\}/, opts )
|
84
|
-
exec_string.gsub!( /\{\{x\}\}/, executable )
|
85
|
-
|
86
|
-
result += `#{exec_string}`
|
87
|
-
else
|
88
|
-
return false
|
89
|
-
end
|
90
|
-
|
91
|
-
result += "\n\n<!-- generated from #{@format} by htmlizer #{@name} -->\n"
|
92
|
-
result
|
93
|
-
end
|
94
|
-
|
95
|
-
def determine_file_format( file )
|
96
|
-
file.fwf_filepath.ext.to_sym
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|