epubforge 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +17 -10
  3. data/VERSION +1 -1
  4. data/bin/epubforge +1 -1
  5. data/config/actions/epub.rb +50 -0
  6. data/config/actions/forge.rb +34 -13
  7. data/config/actions/git.rb +106 -0
  8. data/config/actions/help.rb +13 -13
  9. data/config/actions/html.rb +33 -0
  10. data/config/actions/mobi.rb +60 -0
  11. data/config/actions/new.rb +182 -0
  12. data/config/actions/word_count.rb +26 -24
  13. data/config/{actions → actions_to_ignore}/generate.rb +1 -1
  14. data/config/{actions → actions_to_ignore}/generate_chapter.rb +0 -0
  15. data/config/{actions → actions_to_ignore}/git_backup.rb +2 -2
  16. data/config/{actions → actions_to_ignore}/globals.rb +1 -1
  17. data/config/{actions → actions_to_ignore}/kindle.rb +3 -3
  18. data/config/{actions → actions_to_ignore}/local_action.rb +1 -1
  19. data/config/{actions → actions_to_ignore}/mobify.rb +3 -3
  20. data/config/actions_to_ignore/notes_to_epub.rb +19 -0
  21. data/config/actions_to_ignore/notes_to_kindle.rb +18 -0
  22. data/config/{actions → actions_to_ignore}/spell.rb +1 -1
  23. data/config/{actions → actions_to_ignore}/version.rb +3 -3
  24. data/config/{actions → actions_to_ignore}/wrap_scene_notes_in_hidden_div.rb +1 -1
  25. data/config/converters/epub_to_mobi.calibre.rb +8 -0
  26. data/config/converters/epub_to_mobi.kindlegen.rb +11 -0
  27. data/config/html_translators/default_kramdown.html_translator.rb +9 -0
  28. data/config/html_translators/default_markdown.html_translator.rb +10 -0
  29. data/config/html_translators/default_markdown_pandoc.html_translator.rb +10 -0
  30. data/config/html_translators/default_textile_pandoc.html_translator.rb +8 -0
  31. data/config/html_translators/default_xhtml.html_translator.rb +7 -0
  32. data/config/html_translators/fallback_html.html_translator.rb +9 -0
  33. data/config/html_translators/fallback_markdown.html_translator.rb +8 -0
  34. data/config/html_translators/fallback_textile.html_translator.rb +7 -0
  35. data/config/html_translators/fallback_txt.html_translator.rb +8 -0
  36. data/config/html_translators/fallback_unknown.html_translator.rb +7 -0
  37. data/lib/epubforge.rb +37 -82
  38. data/lib/{action/thor_action.rb → epubforge/action/action.rb} +89 -69
  39. data/lib/epubforge/action/action2.rb +109 -0
  40. data/lib/epubforge/action/action_definition.rb +62 -0
  41. data/lib/epubforge/action/actions_lookup.rb +45 -0
  42. data/lib/epubforge/action/chatterbox.rb +93 -0
  43. data/lib/{action → epubforge/action}/cli_command.rb +2 -2
  44. data/lib/{action → epubforge/action}/cli_sequence.rb +0 -0
  45. data/lib/{action → epubforge/action}/file_transformer.rb +0 -0
  46. data/lib/{action → epubforge/action}/hooks_interface.rb +2 -2
  47. data/lib/{action → epubforge/action}/run_description.rb +12 -9
  48. data/lib/{action → epubforge/action}/runner.rb +23 -24
  49. data/lib/{epub → epubforge/builder}/assets/asset.rb +1 -1
  50. data/lib/{epub → epubforge/builder}/assets/font.rb +1 -1
  51. data/lib/epubforge/builder/assets/html.rb +9 -0
  52. data/lib/{epub → epubforge/builder}/assets/image.rb +1 -1
  53. data/lib/epubforge/builder/assets/markdown.rb +9 -0
  54. data/lib/{epub → epubforge/builder}/assets/page.rb +12 -4
  55. data/lib/{epub → epubforge/builder}/assets/stylesheet.rb +1 -1
  56. data/lib/epubforge/builder/assets/textile.rb +9 -0
  57. data/lib/epubforge/builder/assets/xhtml.rb +9 -0
  58. data/lib/epubforge/builder/builder.rb +134 -0
  59. data/lib/{epub/builder.rb → epubforge/builder/epub.rb} +58 -161
  60. data/lib/epubforge/builder/html.rb +22 -0
  61. data/lib/epubforge/builder/packager.rb +16 -0
  62. data/lib/epubforge/core_extensions/array.rb +2 -0
  63. data/lib/{core_extensions → epubforge/core_extensions}/kernel.rb +0 -0
  64. data/lib/epubforge/core_extensions/nil_class.rb +2 -0
  65. data/lib/epubforge/core_extensions/object.rb +24 -0
  66. data/lib/{core_extensions → epubforge/core_extensions}/string.rb +1 -5
  67. data/lib/{custom_helpers.rb → epubforge/custom_helpers.rb} +0 -1
  68. data/lib/{errors.rb → epubforge/exceptions/errors.rb} +0 -0
  69. data/lib/{project → epubforge/project}/project.rb +23 -17
  70. data/lib/epubforge/utils/action_loader.rb +8 -0
  71. data/lib/epubforge/utils/class_loader.rb +102 -0
  72. data/lib/epubforge/utils/converter.rb +94 -0
  73. data/lib/{utils → epubforge/utils}/downloader.rb +0 -0
  74. data/lib/{utils → epubforge/utils}/file_orderer.rb +0 -0
  75. data/lib/epubforge/utils/file_path.rb +8 -0
  76. data/lib/epubforge/utils/html_translator.rb +126 -0
  77. data/lib/epubforge/utils/html_translator_queue.rb +113 -0
  78. data/lib/epubforge/utils/htmlizer.rb +61 -0
  79. data/lib/{utils → epubforge/utils}/misc.rb +0 -0
  80. data/lib/epubforge/utils/root_path.rb +8 -0
  81. data/lib/epubforge/utils/settings.rb +147 -0
  82. data/lib/epubforge/utils/template_evaluator.rb +7 -0
  83. data/templates/{default/book/afterword.markdown.template → project/book/afterword.markdown} +0 -0
  84. data/templates/project/book/chapter-%0000chapter%.markdown.template +4 -0
  85. data/templates/{default → project}/book/cover.xhtml.template +2 -2
  86. data/templates/{default/book/foreword.markdown.template → project/book/foreword.markdown} +0 -0
  87. data/templates/{default → project}/book/images/cover.png +0 -0
  88. data/templates/{default/book/stylesheets/stylesheet.css.template → project/book/stylesheets/stylesheet.css} +0 -0
  89. data/templates/project/book/title_page.markdown.template +5 -0
  90. data/templates/project/notes/character.%character.name_for_file%.markdown.template +15 -0
  91. data/templates/{default → project}/notes/images/cover.png +0 -0
  92. data/templates/{default/notes/stylesheets/stylesheet.css.template → project/notes/stylesheets/stylesheet.css} +0 -0
  93. data/templates/{default → project}/settings/actions/local_action.rb.example +1 -1
  94. data/templates/project/settings/config.rb.template +70 -0
  95. data/templates/project/settings/html_translators/example_translator.rb +29 -0
  96. data/templates/{default → project}/settings/wordcount.template +1 -1
  97. data/test/answers01.yml +30 -0
  98. data/test/helper.rb +62 -39
  99. data/test/misc/config.rb +5 -7
  100. data/test/test_epubforge.rb +18 -14
  101. data/test/{test_htmlizers.rb → test_html_translators.rb} +4 -8
  102. data/test/test_template_evaluator.rb +42 -0
  103. data/test/test_utils.rb +0 -11
  104. metadata +186 -189
  105. data/config/actions/gitify.rb +0 -72
  106. data/config/actions/init.rb +0 -138
  107. data/config/actions/notes_to_epub.rb +0 -18
  108. data/config/actions/notes_to_kindle.rb +0 -17
  109. data/config/htmlizers.rb +0 -70
  110. data/lib/action/actions_lookup.rb +0 -45
  111. data/lib/core_extensions/array.rb +0 -5
  112. data/lib/core_extensions/nil_class.rb +0 -5
  113. data/lib/core_extensions/object.rb +0 -5
  114. data/lib/epub/assets/html.rb +0 -8
  115. data/lib/epub/assets/markdown.rb +0 -8
  116. data/lib/epub/assets/textile.rb +0 -8
  117. data/lib/epub/assets/xhtml.rb +0 -8
  118. data/lib/epub/packager.rb +0 -16
  119. data/lib/utils/action_loader.rb +0 -7
  120. data/lib/utils/class_loader.rb +0 -102
  121. data/lib/utils/directory_builder.rb +0 -181
  122. data/lib/utils/file_path.rb +0 -152
  123. data/lib/utils/html_translator.rb +0 -100
  124. data/lib/utils/html_translator_queue.rb +0 -70
  125. data/lib/utils/htmlizer.rb +0 -92
  126. data/lib/utils/root_path.rb +0 -20
  127. data/lib/utils/settings.rb +0 -146
  128. data/lib/utils/template_evaluator.rb +0 -20
  129. data/templates/default/book/chapter-%i%.markdown.sequence +0 -4
  130. data/templates/default/book/title_page.markdown.template +0 -4
  131. data/templates/default/notes/character.named.markdown.template +0 -4
  132. data/templates/default/payload.rb +0 -65
  133. data/templates/default/settings/config.rb.form +0 -55
  134. data/templates/default/settings/htmlizers.rb +0 -0
  135. data/test/test_directory_builder.rb +0 -141
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3af4d3450b3369cb3d99d89942078b6b6fffc0f5
4
+ data.tar.gz: 32e50a33bc8ea53caa1d64075c3a0cc4ebe4f5fd
5
+ SHA512:
6
+ metadata.gz: d8cb4d480ea8e8759cd3d0b94fc7bea6ebbb9d3aaa4ca9564e3743c75ddde0d7e8d3bb462e9024c5ef156a24b6038a2185b747874babfddfd966d6f326391485
7
+ data.tar.gz: 0bc3df2a1b8168d504f504270601fa092c81928837308a4f3f704d93a60b91258e7a8bb5c995e722e183c2e915591e5f320fc9cefbbd4a89b08198345531ad16
data/Gemfile CHANGED
@@ -9,18 +9,25 @@ source "http://rubygems.org"
9
9
  # Add dependencies to develop your gem here.
10
10
  # Include everything needed to run rake, tests, features, etc.
11
11
 
12
- gem "xdg"
13
- gem "builder"
12
+ gem "xdg", "~> 2"
13
+ gem "builder", "~> 3"
14
14
  gem "nokogiri", "~> 1.5"
15
- gem "thor"
15
+ gem "thor", "~> 0"
16
+ gem "kramdown", ">= 1.3"
17
+
16
18
  # gem "configurator2"
17
- gem 'fun_with_files'
18
- gem 'fun_with_configurations'
19
+ gem 'fun_with_gems', "~> 0.0"
20
+ gem 'fun_with_configurations', "~> 0.0"
21
+ gem 'fun_with_templates', "~> 0.0"
22
+ gem 'fun_with_string_colors', "~> 0.0"
23
+ gem 'fun_with_patterns', "~> 0.0"
19
24
 
20
25
  group :development do
21
- gem "rdoc", "~> 3.12"
22
- gem "bundler", "~> 1.3.0"
23
- gem "jeweler", "~> 1.8.4"
24
- gem "shoulda", "~> 3.3"
25
- gem "debugger"
26
+ # gem "shoulda", "~> 3.5"
27
+ # gem "rdoc", "~> 3.12"
28
+ # gem "bundler", "~> 1.0"
29
+ # gem "jeweler", "~> 2.0"
30
+ # gem "simplecov", "~> 0", ">= 0.8"
31
+ # gem "debugger", "~> 1", ">= 1.6"
32
+ gem "fun_with_testing", "~> 0.0", ">= 0.0.2"
26
33
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.10
1
+ 0.0.11
data/bin/epubforge CHANGED
@@ -6,5 +6,5 @@ exec_is_in = File.expand_path( File.dirname(__FILE__) )
6
6
  epubforge_loader_file = File.join( exec_is_in, "..", "lib", "epubforge" )
7
7
 
8
8
  require epubforge_loader_file
9
-
9
+
10
10
  EpubForge::Action::Runner.new.exec( *ARGV )
@@ -0,0 +1,50 @@
1
+ module EpubForge
2
+ module Action
3
+ class Epub < Action2
4
+ define_action( "epub" ) do |action|
5
+ # include_standard_options
6
+ action.help( "Create ebooks in various formats from the .markdown files in the project's book/ and notes/ subdirectories." )
7
+ # keyword( "forge" )
8
+ # desc( "forge", "Wraps the project up in a .epub (ebook) file.")
9
+ action.execute do
10
+ epub_common( "book" )
11
+ end
12
+ end
13
+
14
+ define_action( "epub:notes" ) do |action|
15
+ action.help( "Create ebooks for your story bible, instead of your main book" )
16
+
17
+ action.execute do
18
+ epub_common( "notes" )
19
+ end
20
+ end
21
+
22
+ protected
23
+ def epub_common( target, opts = {} )
24
+ # opts[:page_order] ||= project.config["pages"][target]
25
+ case target
26
+ when "book"
27
+ opts[:book_dir] ||= project.book_dir
28
+ outfile = opts.delete(:outfile) || project.filename_for_book.ext("epub")
29
+ when "notes"
30
+ opts[:book_dir] ||= project.notes_dir
31
+ outfile = opts.delete(:outfile) || project.filename_for_notes.ext("epub")
32
+ else
33
+ # Hope the caller knows what it's doing.
34
+ opts[:book_dir] ||= project.book_dir.up.join( target )
35
+ outfile = opts.delete(:outfile) || project.root_dir.join( "#{project.default_project_basename}.#{target}.epub" )
36
+ end
37
+
38
+ opts[:verbose] = verbose?
39
+ builder = EpubForge::Builder::Epub.new( project, opts )
40
+
41
+ builder.build
42
+ builder.package( outfile )
43
+ builder.clean
44
+ say_all_is_well( "Done building epub <#{outfile}>" )
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+
@@ -1,22 +1,43 @@
1
1
  module EpubForge
2
2
  module Action
3
- class Forge < ThorAction
4
- include_standard_options
5
- description "Create ebooks in various formats from the .markdown files in the project's book/ and notes/ subdirectories."
3
+ class Forge < Action2
4
+ define_action( "forge" ) do |action|
5
+ action.help( "Create all book formats" )
6
+
7
+ action.execute do
8
+ raise "todo"
9
+ builder = EpubForge::Builder::Epub.new( project )
10
+ build( builder, project.filename_for_book.ext("epub") )
11
+ end
12
+ end
13
+
14
+ define_action( "forge:notes" ) do |action|
15
+ action.help( "Create all formats of of book's notes.")
16
+
17
+ action.execute do
18
+ raise "todo"
19
+ builder = EpubForge::Builder::Epub.new( project, book_dir: project.notes_dir,
20
+ page_order: project.config[:pages][:notes] )
21
+
22
+ build( builder, project.filename_for_notes.ext("epub") )
23
+ end
24
+ end
6
25
 
7
- desc( "forge", "Wraps the project up in a .epub (ebook) file.")
8
- def forge( *args )
9
- before_start
10
- builder = EpubForge::Epub::Builder.new( @project, :page_order => @project.config["pages"]["book"] )
11
-
26
+ define_action( "forge:formats" ) do |action|
27
+ action.help( "List information about which ebook formats are available." )
28
+
29
+ action.execute do
30
+ puts "TODO!".paint( :bg_red, :white, :bold )
31
+ raise "todo"
32
+ end
33
+ end
34
+
35
+ def build( builder, builds_file )
12
36
  builder.build
13
- builder.package( @project.filename_for_epub_book )
37
+ builder.package( builds_file )
14
38
  builder.clean
15
- puts "Done building epub <#{@project.filename_for_epub_book}>"
39
+ puts "Done building epub <#{builds_file}>"
16
40
  end
17
-
18
- desc( "forge:epub", "Wraps the project up in a .epub (ebook) file." )
19
- alias :epub :forge # I _think_ this will allow me to also use forge:epub as an alias for forge
20
41
  end
21
42
  end
22
43
  end
@@ -0,0 +1,106 @@
1
+ module EpubForge
2
+ module Action
3
+ class Git < Action2
4
+ define_action( "git:save" ) do |action|
5
+ action.help( "commit changes to your project to your repository" )
6
+ action.usage( "git:save 'optional commit message'" )
7
+
8
+ action.execute do
9
+
10
+ end
11
+ end
12
+
13
+
14
+ #
15
+ # class GitBackup < Action
16
+ # description "commit your project to the git repo and back it up"
17
+ # keywords :backup, :save, :commit
18
+ # usage "#{$PROGRAM_NAME} commit <project directory (optional if current dir)> \"optional message\""
19
+ #
20
+ # desc( "do:save", "save to your git repository")
21
+ # def do( project, *args )
22
+ # @project = project
23
+ # @message = args.length > 0 ? args.last : "incremental backup"
24
+ #
25
+ # unless project_already_gitted?
26
+ # say_error "Not a git-backed project. Aborting."
27
+ # say_instruction "Run 'epubforge gitify <project>' to create a backup repository."
28
+ # return false
29
+ # end
30
+ #
31
+ # `cd #{@project.root_dir} && git commit -a -m "#{@message}" && git push`
32
+ # end
33
+ #
34
+ #
35
+
36
+
37
+
38
+ define_action( "git:init" ) do |action|
39
+ action.help( "create a git repository of the project folder on an external host or thumb drive" )
40
+
41
+ action.execute do
42
+ @project = project
43
+ @conf = @project.config
44
+ @gitconf = @conf.git
45
+
46
+ @cli_sequence = CliSequence.new
47
+ @cli_sequence.default( :verbose, true )
48
+ @cli_sequence.default( :local_dir, @project.root_dir )
49
+
50
+
51
+ if project_already_gitted?
52
+ say_error "Already seems to be a git project. delete the .git folder if this is incorrect."
53
+ return false
54
+ end
55
+
56
+ project_name_with_folder = @gitconf["repo_folder"].fwf_filepath
57
+
58
+ if @gitconf["remote_host"]
59
+ remote_host = "#{@gitconf['remote_user']}@#{@gitconf['remote_host']}"
60
+ @cli_sequence.default( :remote, remote_host )
61
+ project_url = "ssh://#{remote_host}#{project_name_with_folder}"
62
+
63
+ @cli_sequence.add_remote_command( "mkdir -p #{project_name_with_folder}", "rm -rf #{project_name_with_folder}" )
64
+ @cli_sequence.add_remote_command( "git --bare init #{project_name_with_folder}" )
65
+ identifier = project_name_with_folder.join( @gitconf["repo_id"] )
66
+ @cli_sequence.add_remote_command( "touch #{identifier}", "rm #{identifier}" ) # undo isn't needed here, since the directory will be wiped out.
67
+ else
68
+ project_url = "file://#{project_name_with_folder}"
69
+ @cli_sequence.add_local_command( "mkdir -p #{project_name_with_folder}", "rm -rf #{project_name_with_folder}" )
70
+ @cli_sequence.add_local_command( "git --bare init #{project_name_with_folder}" )
71
+ identifier = project_name_with_folder.join( @gitconf["repo_id"] )
72
+ @cli_sequence.add_local_command( "touch #{identifier}", "rm #{identifier}" )
73
+ end
74
+
75
+ # running locally
76
+ @cli_sequence.add_local_command "git init", "rm -rf .git"
77
+ @cli_sequence.add_local_command "git remote add origin #{project_url}"
78
+ @cli_sequence.add_local_command "git add ."
79
+ @cli_sequence.add_local_command "git commit -a -m \"Initial commit\""
80
+ @cli_sequence.add_local_command "git config branch.master.remote origin"
81
+ @cli_sequence.add_local_command "git config branch.master.merge refs/heads/master"
82
+ @cli_sequence.add_local_command "git push origin master" # need to be explicit about branch the first time
83
+
84
+ if @cli_sequence.execute
85
+ say_all_is_well( "All done. The url for this project is #{project_url}" )
86
+ else
87
+ say_error( "Command sequence failed." )
88
+ end
89
+ end
90
+ end
91
+
92
+ protected
93
+ def git_remote_exec( cmd )
94
+ say_subtly( "attempting to run remotely: #{cmd}" )
95
+ `cd #{@project.root_dir} && ssh #{@gitconf["remote_user"]}@#{@gitconf["remote_host"]} "#{cmd}"`
96
+ say( "Success: #{$?.success?}")
97
+ end
98
+
99
+ def git_local_exec( cmd )
100
+ say_subtly( "attempting to run locally: #{cmd}" )
101
+ `cd #{@project.root_dir} && #{cmd}`
102
+ say( "Success: #{$?.success?}")
103
+ end
104
+ end
105
+ end
106
+ end
@@ -1,18 +1,18 @@
1
1
  module EpubForge
2
2
  module Action
3
- class Help < ThorAction
4
- project_not_required
5
-
6
- desc( "help", "print out help for the various actions.")
7
- def help( *args )
8
- say_instruction "epubforge [action] [folder]"
9
- say_instruction "\tActions:"
10
- say_instruction ThorAction.command_to_action_classes.inspect
11
- # for action in ThorAction.c
12
- # say_instruction "\t( #{action.keywords.join(" | ")} ) :"
13
- # say_instruction "\t\tDescription: #{action.description}"
14
- # say_instruction "\t\tUsage: #{action.usage}\n"
15
- # end
3
+ class Help < Action2
4
+ define_action( "help" ) do |action|
5
+ action.project_not_required
6
+ action.help( "Print out information for various actions." )
7
+
8
+ action.execute do |*args|
9
+ say_instruction "epubforge [action] [folder]"
10
+ say_instruction "Actions:"
11
+ for keyword, action in Action2.loader_pattern_registry
12
+ say_instruction " #{keyword} : #{action.help}"
13
+ say_instruction " usage: #{$PROGRAM_NAME} #{action.usage}" unless action.usage.fwf_blank?
14
+ end
15
+ end
16
16
  end
17
17
  end
18
18
  end
@@ -0,0 +1,33 @@
1
+ module EpubForge
2
+ module Action
3
+ class HTML < Action2
4
+ define_action( "html" ) do |action|
5
+ action.help( "Create an HTML version of your book" )
6
+ action.execute do
7
+ book_dir = @project.root_dir.join( "book" )
8
+ filename = @project.filename_for_book.ext( "html" )
9
+ html_common( book_dir, filename )
10
+ end
11
+
12
+ define_action( "html:notes" ) do |action|
13
+ action.help( "Create an HTML version of your notebook" )
14
+ action.execute do
15
+ book_dir = @project.root_dir.join( "notes" )
16
+ filename = @project.filename_for_notes.ext( "html" )
17
+ html_common( book_dir, filename )
18
+ end
19
+ end
20
+
21
+ protected
22
+ def html_common( book_dir, filename )
23
+ builder = EpubForge::Builder::Html.new( project, {:book_dir => book_dir} )
24
+
25
+ builder.build
26
+ builder.package( filename )
27
+ builder.clean
28
+ puts "Done building #{filename}.".paint(:green)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,60 @@
1
+ module EpubForge
2
+ module Action
3
+ class Mobi < Action2
4
+ define_action( "mobi" ) do |action|
5
+ action.help( "Converts .epub to .mobi." )
6
+
7
+ action.execute do
8
+ converters = Utils::Converter.converts( :epub, :mobi )
9
+
10
+ # TODO: Uses the first converter it finds. Suboptimal.
11
+ for converter in converters
12
+ if converter.is_executable_installed?
13
+ @converter = converter
14
+ break
15
+ end
16
+ end
17
+ mobi_convert_common
18
+ end
19
+ end
20
+
21
+ define_action( "mobi:convert:calibre" ) do |action|
22
+ action.help( "Converts .epub to .mobi, using Calibre's ebook-convert utility" )
23
+ action.execute do
24
+ @converter = Utils::Converter[:epub_to_mobi_calibre]
25
+ mobi_convert_common
26
+ end
27
+ end
28
+
29
+ define_action( "mobi:convert:kindlegen" ) do |action|
30
+ action.execute do
31
+ @converter = Utils::Converter[:epub_to_mobi_kindlegen]
32
+ mobi_convert_common
33
+ end
34
+ end
35
+
36
+ protected
37
+ def mobi_convert_common
38
+ src = @project.filename_for_book.ext( "epub" )
39
+ dest = @project.filename_for_book.ext( "mobi" )
40
+
41
+ unless src.file?
42
+ puts "Failure: source .epub doesn't exist: #{src}".pain(:red)
43
+ end
44
+
45
+ # Sigh, Kindlegen is stupid
46
+ if @converter.label == :epub_to_mobi_kindlegen
47
+ dest = dest.basename
48
+ end
49
+
50
+ conversion = @converter.convert( src, { :dest => dest, :command_line_options => "" } )
51
+
52
+ if conversion
53
+ puts "Success!".paint(:green)
54
+ else
55
+ puts "Failure!".paint(:red)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,182 @@
1
+ module EpubForge
2
+ module Action
3
+ class New < Action2
4
+ define_action( "new" ) do |action|
5
+ action.project_not_required
6
+
7
+ action.help( "Create a brand new project." )
8
+ action.usage( "new <DIRECTORY_NAME>" )
9
+ action.default( :verbose, false )
10
+
11
+ action.execute do
12
+ if @project.is_a?(Project)
13
+ say_error "The directory given (#{@project.root_dir}) is already an EpubForge project. Quitting."
14
+ false
15
+ elsif parse_args( *args )
16
+ get_template_filepath_from_options
17
+ configure_configuration( @opts[:answers] || {} )
18
+ FunWith::Templates::TemplateEvaluator.write( @template_dir, self.destination_root_filepath, @template_options )
19
+ else
20
+ false
21
+ end
22
+ end
23
+ end
24
+ #
25
+ #
26
+ #
27
+ #
28
+ #
29
+ # src_dirs = src_entries.select{ |d| @template_dir.join(d).directory? }.uniq
30
+ #
31
+ # for dir in src_dirs
32
+ # puts "creating dir #{dir}"
33
+ # empty_directory( self.destination_root_filepath.join( dir ) )
34
+ # debugger unless self.destination_root_filepath.join( dir ).directory?
35
+ # 5
36
+ # end
37
+ #
38
+ # debugger unless self.destination_root_filepath.directory?
39
+ #
40
+ # for entry in src_entries - src_dirs
41
+ # case entry.ext
42
+ # when "template"
43
+ # dst = self.destination_root_filepath.join( entry ).without_ext
44
+ # puts dst.inspect
45
+ # puts entry.inspect
46
+ # FunWith::Files::FilePath.template( entry, dst )
47
+ # when "sequence"
48
+ # @chapter_count ||= @opts[:answers][:chapter_count] if @opts[:answers]
49
+ # @chapter_count ||= ask_prettily("Setting up chapter files.\n How many chapters will your book have (you can add more later)? >>> ").to_i
50
+ #
51
+ # 1.upto( @chapter_count ) do |i|
52
+ # dst = self.destination_root_filepath.join( entry ).gsub( /%i%/, sprintf( "%04i", i) ).without_ext
53
+ # FunWith::Files::FilePath.template( entry, dst, {:i => i} )
54
+ # end
55
+ # when "form"
56
+ # configure_configuration( @opts[:answers] || {} )
57
+ # dst = self.destination_root_filepath.join( entry ).without_ext
58
+ # FunWith::Files::FilePath.template( entry, dst, @template_options )
59
+ # say_all_is_well( "Your configuration is all set up!" )
60
+ # say_instruction( "run 'epubforge gitify' to initialize the backup repository." )
61
+ # else
62
+ # copy_file( entry, self.destination_root_filepath.join( entry ) )
63
+ # end
64
+ # end
65
+ # end
66
+
67
+ protected
68
+ def configure_configuration(opts = {})
69
+ say_instruction( "Don't think too hard about these next few questions. You can always change your mind by editing settings/config" )
70
+
71
+ opts[:book] ||= {}
72
+ opts[:book][:title] ||= ask_prettily( "What is the name of your book?" )
73
+ opts[:book][:author] ||= ask_prettily( "What is the name of the author?" )
74
+ opts[:license] ||= ask_from_menu( "What license do you want your book under?", [ "All Rights Reserved",
75
+ "Creative Commons Non-Commercial, No Derivatives License",
76
+ "Creative Commons Non-Commercial, Share-Alike License",
77
+ "GNU Free Documentation License",
78
+ "Public Domain",
79
+ "Other" ] )
80
+ if opts[:license] == "Other"
81
+ opts[:license] = ask_prettily( "Type in the license you wish to use : " )
82
+ end
83
+
84
+ opts[:chapter] ||= (1..(ask_prettily( "How many chapters?" ).to_i))
85
+
86
+ @template_options = opts
87
+
88
+ if git_installed?
89
+ if opts[:use_git] || opts[:use_git].nil? && yes_prettily?( "Do you want to back up your project using git?" )
90
+ configure_git( opts[:git] || {} )
91
+ end
92
+ else
93
+ warn( "The program 'git' must be installed and locatable if you want epubforge to back up your project." )
94
+ end
95
+
96
+ configure_character
97
+ end
98
+
99
+
100
+
101
+ def configure_git( opts = {} )
102
+ opts[:remote] = "Back up to a remote host."
103
+ opts[:thumb] = "Back up to an external or thumb drive."
104
+ opts[:backup_type] ||= ask_from_menu( "Where would you like to back up your project to?",
105
+ [ opts[:remote],
106
+ opts[:thumb] ] )
107
+
108
+ opts[:repo_id] ||= rand(16**32).to_s(16)
109
+
110
+ if opts[:backup_type] == opts[:remote]
111
+ opts[:host] ||= ask_prettily("Enter the name of the remote host : ")
112
+ opts[:user] ||= ask_prettily("Enter your user name : ")
113
+ opts[:repo] ||= ask_prettily("Enter the name of the folder on the remote host. A folder called #{backup_folder_name} will be created there : ")
114
+ elsif opts[:backup_type] == opts[:thumb]
115
+ opts[:repo] ||= ask_prettily("Enter the full path to the backup folder. A folder called #{backup_folder_name} will be created there: ")
116
+ else
117
+ say_error("I'm confused by the requested backup style <#{opts[:backup_type]}>. Skipping git configuration.")
118
+ opts = nil
119
+ return false
120
+ end
121
+
122
+ # TODO: What if the target file system uses a different file separator?
123
+ opts[:repo] = opts[:repo].fwf_filepath.join( backup_folder_name ) if opts[:repo].is_a?(String)
124
+ @template_options[:git] = opts
125
+ true
126
+ end
127
+
128
+ def configure_character
129
+ @template_options[:character] = {
130
+ :name => "Mr. Example Protagonist",
131
+ :name_for_file => "mister_example_protagonist",
132
+ :description => "Tall, red hair, angry complexion, indifferent to fashion and hygiene.",
133
+ :summary => "Example once drove a man to drink, because the guy's liver once killed his dad.",
134
+ :age => 23
135
+ }
136
+ end
137
+
138
+ def backup_folder_name
139
+ (@template_options[:book][:title] || "").epf_underscorize + ".epubforge.git"
140
+ end
141
+
142
+ # Expects the following arguments: 1:<project directory (shouldn't exist)>, 2: options hash.
143
+ # Options hash includes:
144
+ def parse_args( *args )
145
+ @opts = args.last.is_a?(Hash) ? args.pop : {}
146
+ project_root = args.shift
147
+
148
+ case project_root
149
+ when NilClass
150
+ say_error "No destination directory given."
151
+ return false
152
+ when Project
153
+ say_error "You seem to be creating a project within a project. Cut it out."
154
+ return false
155
+ end
156
+
157
+ self.destination_root_filepath = project_root.fwf_filepath
158
+
159
+ if self.destination_root_filepath.exist? &&
160
+ (!(self.destination_root_filepath.empty?) || !(self.destination_root_filepath.directory?))
161
+ say_error "This action must create a new directory or act upon an empty directory. Quitting."
162
+ return false
163
+ end
164
+
165
+ true
166
+ end
167
+
168
+ # TODO: Shouldn't the user settings / project settings also be searchable?
169
+ # Wouldn't preference be given to project, then user settings?
170
+ def get_template_filepath_from_options
171
+ @template_to_use = (@opts[:template] || "project").fwf_filepath # TODO: should turn into an option
172
+ if @template_to_use.absolute?
173
+ @template_dir = @template_to_use
174
+ else
175
+ @template_dir = EpubForge.root.join( "templates", @template_to_use )
176
+ end
177
+
178
+
179
+ end
180
+ end
181
+ end
182
+ end