git-scribe 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. data/.gitignore +1 -0
  2. data/Rakefile +31 -0
  3. data/SPEC.asciidoc +126 -0
  4. data/TODO.txt +29 -0
  5. data/bin/git-scribe +2 -1
  6. data/docbook-xsl/.CatalogManager.properties.example +61 -0
  7. data/docbook-xsl/.urilist +1 -0
  8. data/git-scribe.gemspec +32 -0
  9. data/lib/git-scribe.rb +21 -315
  10. data/lib/git-scribe/check.rb +60 -0
  11. data/lib/git-scribe/cli.rb +84 -0
  12. data/lib/git-scribe/generate.rb +222 -0
  13. data/lib/git-scribe/init.rb +16 -0
  14. data/lib/git-scribe/version.rb +3 -0
  15. data/template/.gitignore +1 -0
  16. data/template/.gitscribe +5 -0
  17. data/test/check_test.rb +12 -0
  18. data/test/gen_test.rb +78 -0
  19. data/test/init_test.rb +36 -0
  20. data/test/test_helper.rb +44 -0
  21. metadata +49 -161
  22. data/example/book/big.asc +0 -5604
  23. data/example/book/holmes.asc +0 -12983
  24. data/example/output/META-INF/container.xml +0 -6
  25. data/example/output/OEBPS/ar01s02.html +0 -15
  26. data/example/output/OEBPS/ar01s03.html +0 -3
  27. data/example/output/OEBPS/content.opf +0 -21
  28. data/example/output/OEBPS/index.html +0 -5
  29. data/example/output/OEBPS/toc.ncx +0 -37
  30. data/example/output/a_case_of_identity.html +0 -725
  31. data/example/output/a_example_appendix.html +0 -63
  32. data/example/output/a_migration_notes.html +0 -95
  33. data/example/output/apa.html +0 -20
  34. data/example/output/apb.html +0 -6
  35. data/example/output/apc.html +0 -24
  36. data/example/output/apd.html +0 -30
  37. data/example/output/ape.html +0 -26
  38. data/example/output/apf.html +0 -9
  39. data/example/output/apg.html +0 -42
  40. data/example/output/aph.html +0 -89
  41. data/example/output/ar01s02.html +0 -12
  42. data/example/output/ar01s03.html +0 -34
  43. data/example/output/ar01s04.html +0 -77
  44. data/example/output/ar01s05.html +0 -272
  45. data/example/output/ar01s06.html +0 -35
  46. data/example/output/ar01s07.html +0 -105
  47. data/example/output/ar01s08.html +0 -33
  48. data/example/output/ar01s09.html +0 -12
  49. data/example/output/ar01s10.html +0 -14
  50. data/example/output/ar01s11.html +0 -34
  51. data/example/output/ar01s12.html +0 -63
  52. data/example/output/ar01s13.html +0 -156
  53. data/example/output/ar01s14.html +0 -330
  54. data/example/output/ar01s15.html +0 -22
  55. data/example/output/ar01s16.html +0 -27
  56. data/example/output/ar01s17.html +0 -94
  57. data/example/output/ar01s18.html +0 -359
  58. data/example/output/ar01s19.html +0 -373
  59. data/example/output/ar01s20.html +0 -27
  60. data/example/output/ar01s21.html +0 -33
  61. data/example/output/ar01s22.html +0 -351
  62. data/example/output/ar01s23.html +0 -21
  63. data/example/output/ar01s24.html +0 -69
  64. data/example/output/ar01s25.html +0 -60
  65. data/example/output/ar01s26.html +0 -217
  66. data/example/output/ar01s27.html +0 -88
  67. data/example/output/ar01s28.html +0 -237
  68. data/example/output/ar01s29.html +0 -68
  69. data/example/output/ar01s30.html +0 -154
  70. data/example/output/ar01s31.html +0 -6
  71. data/example/output/ar01s32.html +0 -22
  72. data/example/output/ar01s33.html +0 -209
  73. data/example/output/asciidoc_backends.html +0 -190
  74. data/example/output/asciidoc_document_types.html +0 -131
  75. data/example/output/attribute_entries.html +0 -185
  76. data/example/output/attribute_lists.html +0 -157
  77. data/example/output/attribute_references.html +0 -414
  78. data/example/output/attributelist_element.html +0 -143
  79. data/example/output/b_packager_notes.html +0 -68
  80. data/example/output/bi01.html +0 -18
  81. data/example/output/big.asc +0 -5604
  82. data/example/output/block_element_definitions.html +0 -448
  83. data/example/output/block_titles.html +0 -83
  84. data/example/output/blockid_element.html +0 -80
  85. data/example/output/book.asc +0 -5604
  86. data/example/output/book.epub +0 -0
  87. data/example/output/book.fo +0 -3788
  88. data/example/output/book.html +0 -8793
  89. data/example/output/book.xml +0 -8265
  90. data/example/output/c_asciidoc_safe_mode.html +0 -105
  91. data/example/output/callouts.html +0 -214
  92. data/example/output/catalog +0 -10
  93. data/example/output/colophon.html +0 -397
  94. data/example/output/configuration_files.html +0 -672
  95. data/example/output/converting_docbook_to_other_file_formats.html +0 -324
  96. data/example/output/d_using_asciidoc_with_non-english_languages.html +0 -107
  97. data/example/output/delimited_blocks.html +0 -455
  98. data/example/output/document_attributes.html +0 -95
  99. data/example/output/document_processing.html +0 -116
  100. data/example/output/document_structure.html +0 -493
  101. data/example/output/e_vim_syntax_highlighter.html +0 -111
  102. data/example/output/example_bibliography.html +0 -82
  103. data/example/output/example_colophon.html +0 -58
  104. data/example/output/example_glossary.html +0 -73
  105. data/example/output/example_index.html +0 -108
  106. data/example/output/f_attribute_options.html +0 -129
  107. data/example/output/filters.html +0 -179
  108. data/example/output/footnotes.html +0 -103
  109. data/example/output/g_diagnostics.html +0 -148
  110. data/example/output/generating_plain_text_files.html +0 -68
  111. data/example/output/getting_started.html +0 -87
  112. data/example/output/glossary.html +0 -95
  113. data/example/output/go01.html +0 -24
  114. data/example/output/h_backend_attributes.html +0 -308
  115. data/example/output/help_commands.html +0 -96
  116. data/example/output/holmes.asc +0 -12983
  117. data/example/output/image/octocat_professor.png +0 -0
  118. data/example/output/include/hello.c +0 -10
  119. data/example/output/index.html +0 -656
  120. data/example/output/indexes.html +0 -104
  121. data/example/output/intrinsic_attributes.html +0 -165
  122. data/example/output/ix01.html +0 -3
  123. data/example/output/lists.html +0 -666
  124. data/example/output/macros.html +0 -737
  125. data/example/output/manpage_documents.html +0 -124
  126. data/example/output/master.css +0 -281
  127. data/example/output/mathematical_formulas.html +0 -125
  128. data/example/output/page.html +0 -60
  129. data/example/output/paragraphs.html +0 -192
  130. data/example/output/pr01.html +0 -3
  131. data/example/output/source_code_highlighting.html +0 -59
  132. data/example/output/stylesheets/handbookish-quirks.css +0 -0
  133. data/example/output/stylesheets/handbookish.css +0 -233
  134. data/example/output/tables.html +0 -797
  135. data/example/output/text_formatting.html +0 -273
  136. data/example/output/the_adventure_of_the_beryl_coronet.html +0 -968
  137. data/example/output/the_adventure_of_the_blue_carbuncle.html +0 -825
  138. data/example/output/the_adventure_of_the_copper_beeches.html +0 -998
  139. data/example/output/the_adventure_of_the_engineer_s_thumb.html +0 -851
  140. data/example/output/the_adventure_of_the_noble_bachelor.html +0 -861
  141. data/example/output/the_adventure_of_the_speckled_band.html +0 -1015
  142. data/example/output/the_boscombe_valley_mystery.html +0 -974
  143. data/example/output/the_first_chapter.html +0 -110
  144. data/example/output/the_five_orange_pips.html +0 -776
  145. data/example/output/the_man_with_the_twisted_lip.html +0 -946
  146. data/example/output/the_red-headed_league.html +0 -950
  147. data/example/output/the_second_chapter.html +0 -95
  148. data/example/output/the_third_chapter.html +0 -58
  149. data/example/output/tips_and_tricks.html +0 -452
  150. data/example/output/title.html +0 -120
  151. data/example/output/titles.html +0 -126
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ example/output
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ def command?(command)
2
+ system("type #{command} > /dev/null 2>&1")
3
+ end
4
+
5
+ #
6
+ # Tests
7
+ #
8
+
9
+ task :default => :test
10
+
11
+ desc "Run the test suite"
12
+ task :test do
13
+ sh('turn test/**/*_test.rb')
14
+ end
15
+
16
+
17
+ #
18
+ # Publishing
19
+ #
20
+
21
+ desc "Push a new version to Gemcutter"
22
+ task :publish do
23
+ require 'git-scribe/version'
24
+
25
+ sh "gem build git-scribe.gemspec"
26
+ sh "gem push git-scribe-#{GitScribe::Version}.gem"
27
+ sh "git tag v#{GitScribe::Version}"
28
+ sh "git push origin v#{GitScribe::Version}"
29
+ sh "git push origin master"
30
+ end
31
+
data/SPEC.asciidoc ADDED
@@ -0,0 +1,126 @@
1
+ The Dream
2
+ =========
3
+
4
+ This is where I'm documenting basically what I want the README to eventually look like. This is sort of my Document Driven Development file. I'm trying to envision what the git-scribe project should look like as I write the tool. I didn't want it to be in the readme yet so as not to confuse people. All the commands are just ideas and what not. If you have an idea of how you would like things to look, add them here and send a pull request.
5
+
6
+ I want to get the full workflows worked out here (with technical details) before I even try to implement them.
7
+
8
+ Start a Book
9
+ ============
10
+
11
+ $ git scribe init (--type=[code,math]) (--license=[public,cc]) (--lang=en) [project]
12
+
13
+ Generates a skeleton, license file and readmes with instructions for authors and contributors.
14
+ Also records version of scribe workflow we're using into .gitscribe file.
15
+
16
+ * shows cheat-sheet of how to use grep, tag, diff (--word)
17
+
18
+ Work on a Book
19
+ ==============
20
+
21
+ $ git scribe check
22
+
23
+ Run checks to make sure you have all the tools you need and your system can do stuff.
24
+
25
+ $ git scribe register (--role=[author,reviewer,editor,translator])
26
+
27
+ Register yourself and your role in this book.
28
+ kept in .git/scribe
29
+
30
+ To Do List
31
+ ==========
32
+
33
+ $ git scribe todo
34
+
35
+ * lists boilerplate you still haven't filled out
36
+ (title, author, description, chapter, cover, bio, biblio, price, license, etc)
37
+ most of that is kept in .gitscribe
38
+
39
+ Writing
40
+ =======
41
+
42
+ $ git scribe new chapter
43
+
44
+ Editing
45
+ =======
46
+
47
+ $ git scribe review
48
+
49
+ TODO: address technical reviewing and copy-editing
50
+
51
+ Translating - Translator
52
+ ========================
53
+
54
+ $ git scribe trans start (--edition=1.1) de
55
+
56
+ Sets up pre-commit hook to check that commit message is formatted correctly, copies over main language to 'de'
57
+
58
+ http://en.wikipedia.org/wiki/IETF_language_tag
59
+
60
+ $ git scribe trans changes (--since=2010-01-01)
61
+
62
+ $ git scribe trans done SHA
63
+
64
+ Translating - Maintainer
65
+ ========================
66
+
67
+ $ git scribe trans complete
68
+
69
+ See which translations are what percent complete.
70
+
71
+ - get list of translators for each translation
72
+
73
+ Editions
74
+ ========
75
+ This is meant to be done infrequently - like an edition of a book or a major version of a framework that is being documented. Publishing editions too often makes work difficult on translators, so be prudent.
76
+
77
+ $ git scribe --tool-version=1.7 publish [major|minor]
78
+
79
+ Tags the edition with the next major or minor number, generates a branch for maintainance for this edition.
80
+
81
+ Generate Media
82
+ ==============
83
+
84
+ $ git scribe gen (--lang=de) (--edition=1.0) [site,pdf,mobi,epub]
85
+
86
+ OR
87
+
88
+ $ git push origin
89
+
90
+ Sell
91
+ ====
92
+
93
+ $ git scribe sell --price=8.00 [--lang=de] (ibooks,kindle,nook,lulu)
94
+
95
+
96
+ Layout
97
+ ======
98
+
99
+ The layout that the `git scribe init` produces looks like this:
100
+
101
+ [source]
102
+ ----
103
+ * book/
104
+ |`--* book.asc
105
+ |`--* 01_first_chapter.asc
106
+ |`--* 02_second_chapter.asc
107
+ |`--* 99_backmatter.asc
108
+ |`--* image/
109
+ | `--* 01.01-example-image.png
110
+ | `--* 01.02-another-image.png
111
+ | `--* 02.01-an-image.png
112
+ |`--* include/
113
+ | `--* 02.01-code.c
114
+ * style/
115
+ |`--* style.css
116
+ * site/
117
+ |`--* layout.html
118
+ * test/
119
+ |`--* 01_test.rb
120
+ * LICENSE.txt
121
+ * README.asciidoc
122
+ * .gitscribe
123
+ ----
124
+
125
+ Not all of those files would be generated (like the test files and the site files which are overrides for the site templates), but examples would and it would give a usable starting point for new authorship. This example would be a valid and somewhat complex layout.
126
+
data/TODO.txt ADDED
@@ -0,0 +1,29 @@
1
+ To-Do List
2
+ =============
3
+
4
+ * custom site layouts
5
+ * custom/alternate themes (stylesheets)
6
+ * mobi generation
7
+ * cover page for site (author, about, etc)
8
+ * book cover (w/template)
9
+ * github pages publishing
10
+ * checking for proper tools
11
+ * book search
12
+ * math formula
13
+ * generate different languages from branches/tags (site, epub, mobi)
14
+
15
+ * use options library
16
+
17
+ * workflow
18
+ - review / copy editing
19
+ - translation
20
+ - edition release
21
+ - maint branches (pegging to software revs)
22
+
23
+ * amazon/ibooks/lulu integration
24
+
25
+ * site comments
26
+ * github-side generation
27
+ * external auto-publishing / monetization (?)
28
+ * docbook import / direct from docbook
29
+
data/bin/git-scribe CHANGED
@@ -2,5 +2,6 @@
2
2
  $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
3
 
4
4
  require 'git-scribe'
5
+ require 'git-scribe/cli'
5
6
 
6
- GitScribe.start
7
+ GitScribe.new.run
@@ -0,0 +1,61 @@
1
+ ########################################################################
2
+ # CatalogManager provides an interface to the catalog properties.
3
+ # Properties can come from two places: from system properties or
4
+ # from a CatalogManager.properties file. This class provides a
5
+ # transparent interface to both, with system properties preferred
6
+ # over property file values.
7
+
8
+ #######################################################################
9
+ # Catalog Files:
10
+ # The semicolon-delimited list of catalog files.
11
+ # Example: catalogs=/etc/xml/catalog;~/catalog.xml
12
+
13
+ catalogs=
14
+
15
+ #######################################################################
16
+ # Relative Catalogs:
17
+ # If false, relative catalog URIs are made absolute with respect to the
18
+ # base URI of the CatalogManager.properties file. This setting only
19
+ # applies to catalog URIs obtained from the catalogs property in the
20
+ # CatalogManager.properties file
21
+ # Example: relative-catalogs = [yes|no]
22
+
23
+ relative-catalogs=yes
24
+
25
+ #######################################################################
26
+ # Verbosity:
27
+ # If non-zero, the Catalog classes will print informative and debugging
28
+ # messages. The higher the number, the more messages.
29
+ # Example: verbosity = [0..99]
30
+
31
+ verbosity=0
32
+
33
+ #######################################################################
34
+ # Prefer:
35
+ # Which identifier is preferred, "public" or "system"?
36
+ # Example: xml.catalog.prefer = [public|system]
37
+
38
+ prefer=system
39
+
40
+ #######################################################################
41
+ # Static-catalog:
42
+ # Should a single catalog be constructed for all parsing, or should a
43
+ # different catalog be created for each parser?
44
+ # Example: static-catalog = [yes|no]
45
+
46
+ static-catalog=yes
47
+
48
+ #######################################################################
49
+ # Allow-oasis-xml-catalog-pi
50
+ # If the source document contains "oasis-xml-catalog" processing
51
+ # instructions, should they be used?
52
+ # Example: allow-oasis-xml-catalog-pi = [yes|no]
53
+
54
+ allow-oasis-xml-catalog-pi=yes
55
+
56
+ #######################################################################
57
+ # catalog-class-name
58
+ # If you're using the convenience classes
59
+ # org.apache.xml.resolver.tools.*, this setting allows you to specify
60
+ # an alternate class name to use for the underlying catalog.
61
+ # Example: catalog-class-name=org.apache.xml.resolver.Resolver
@@ -0,0 +1 @@
1
+ . http://docbook.sourceforge.net/release/xsl/current/
@@ -0,0 +1,32 @@
1
+ $LOAD_PATH.unshift 'lib'
2
+
3
+ files = `git ls-files`.
4
+ split("\n").
5
+ sort
6
+
7
+ puts files
8
+
9
+ # piece file back together and write...
10
+ Gem::Specification.new do |s|
11
+ s.name = "git-scribe"
12
+ s.version = "0.0.5"
13
+ s.date = Time.now.strftime('%Y-%m-%d')
14
+ s.summary = "git-scribe is an authors toolkit for writing and publishing books"
15
+ s.homepage = "http://github.com/schacon/git-scribe"
16
+ s.email = "schacon@gmail.com"
17
+ s.authors = [ "Scott Chacon" ]
18
+ s.has_rdoc = false
19
+
20
+ s.files = files
21
+
22
+ s.executables = %w( git-scribe )
23
+
24
+ s.description = <<desc
25
+ git-scribe is a workflow tool for starting, writing, reviewing and publishing
26
+ multiple forms of a book. it allows you to use asciidoc plain text markup to
27
+ write, review and translate a work and provides a simple toolkit for generating
28
+ common digital outputs for publishing - epub, mobi, pdf and html. it is also
29
+ integrated into github functionality, letting you automate the publishing and
30
+ collaboration process.
31
+ desc
32
+ end
data/lib/git-scribe.rb CHANGED
@@ -1,175 +1,39 @@
1
1
  require 'rubygems'
2
2
  require 'nokogiri'
3
3
  require 'liquid'
4
- require 'subcommand'
4
+
5
+ require 'git-scribe/generate'
6
+ require 'git-scribe/check'
7
+ require 'git-scribe/init'
5
8
 
6
9
  require 'fileutils'
7
10
  require 'pp'
8
11
 
9
12
  class GitScribe
10
13
 
11
- include Subcommands
14
+ include Init
15
+ include Check
16
+ include Generate
17
+
18
+ attr_accessor :subcommand, :args, :options
19
+ attr_reader :info
12
20
 
13
21
  BOOK_FILE = 'book.asc'
14
22
  OUTPUT_TYPES = ['pdf', 'epub', 'mobi', 'html', 'site']
15
23
  SCRIBE_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
16
24
 
17
25
  def initialize
18
-
26
+ @subcommand = nil
27
+ @args = []
19
28
  @options = {}
20
- global_options do |opts|
21
- opts.banner = "Usage: #{$0} [options] [subcommand [options]]"
22
- opts.description = "git-scribe helps you write books with the power of Git"
23
- opts.separator ""
24
- opts.separator "Global options are:"
25
- opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
26
- @options[:verbose] = v
27
- end
28
- end
29
-
30
- command :init do |opts|
31
- opts.banner = "Usage: git scribe init (directory)"
32
- opts.description = "initialize a new book layout"
33
- opts.on("-l", "--lang", "choose a default language (en)") do |v|
34
- @options[:lang] = lang || 'en'
35
- end
36
- end
37
-
38
- command :gen do |opts|
39
- opts.banner = "Usage: git scribe gen [options]"
40
- opts.description = "generate digital formats"
41
- end
42
-
43
- @command = opt_parse
44
- end
45
-
46
- def self.start
47
- GitScribe.new.run
48
- end
49
-
50
- def run
51
- if @command && self.respond_to?(@command)
52
- self.send @command
53
- else
54
- help
55
- end
56
29
  end
57
30
 
58
31
  ## COMMANDS ##
59
-
60
32
 
61
33
  def die(message)
62
34
  raise message
63
35
  end
64
36
 
65
- # start a new scribe directory with skeleton structure
66
- def init
67
- name = ARGV.shift
68
- die("needs a directory name") if !name
69
- die("directory already exists") if File.exists?(name)
70
-
71
- puts "inititalizing #{name}"
72
- from_stdir = File.join(SCRIBE_ROOT, 'template')
73
- FileUtils.cp_r from_stdir, name
74
- end
75
-
76
- # check that we have everything needed
77
- def check
78
- # check for asciidoc
79
- if !check_can_run('asciidoc')
80
- puts "asciidoc is not present, please install it for anything to work"
81
- else
82
- puts "asciidoc - ok"
83
- end
84
-
85
- # check for xsltproc
86
- if !check_can_run('xsltproc --version')
87
- puts "xsltproc is not present, please install it for html generation"
88
- else
89
- puts "xsltproc - ok"
90
- end
91
-
92
- # check for a2x - should be installed with asciidoc, but you never know
93
- if !check_can_run('a2x')
94
- puts "a2x is not present, please install it for epub generation"
95
- else
96
- puts "a2x - ok"
97
- end
98
-
99
- # check for fop
100
- if !check_can_run('fop -version')
101
- puts "fop is not present, please install for PDF generation"
102
- else
103
- puts "fop - ok"
104
- end
105
- end
106
-
107
- def check_can_run(command)
108
- `#{command} 2>&1`
109
- $?.exitstatus == 0
110
- end
111
- # generate the new media
112
- def gen
113
- type = ARGV.shift || 'all'
114
- prepare_output_dir
115
-
116
- gather_and_process
117
-
118
- types = type == 'all' ? OUTPUT_TYPES : [type]
119
-
120
- output = []
121
- Dir.chdir("output") do
122
- types.each do |out_type|
123
- call = 'do_' + out_type
124
- if self.respond_to? call
125
- self.send call
126
- else
127
- puts "NOT A THING: #{call}"
128
- end
129
- end
130
- # clean up
131
- `rm #{BOOK_FILE}`
132
- end
133
- end
134
-
135
- def prepare_output_dir
136
- Dir.mkdir('output') rescue nil
137
- Dir.chdir('output') do
138
- Dir.mkdir('stylesheets') rescue nil
139
- puts SCRIBE_ROOT
140
- from_stdir = File.join(SCRIBE_ROOT, 'stylesheets')
141
- pp from_stdir
142
- FileUtils.cp_r from_stdir, '.'
143
- end
144
- end
145
-
146
- def a2x(type)
147
- "a2x -f #{type} -d book "
148
- end
149
-
150
- def a2x_wss(type)
151
- a2x(type) + " --stylesheet=stylesheets/handbookish.css"
152
- end
153
-
154
- def do_pdf
155
- puts "GENERATING PDF"
156
- # TODO: syntax highlighting (fop?)
157
- puts `asciidoc -b docbook #{BOOK_FILE}`
158
- strparams = {'callout.graphics' => 0,
159
- 'navig.graphics' => 0,
160
- 'admon.textlabel' => 1,
161
- 'admon.graphics' => 0}
162
- param = strparams.map { |k, v| "--stringparam #{k} #{v}" }.join(' ')
163
- puts cmd = "xsltproc --nonet #{param} --output #{local('book.fo')} #{base('docbook-xsl/fo.xsl')} #{local('book.xml')}"
164
- puts `#{cmd}`
165
- cmd = "fop -fo #{local('book.fo')} -pdf #{local('book.pdf')}"
166
- puts `#{cmd}`
167
- #puts `#{a2x('pdf')} -v --fop #{BOOK_FILE}`
168
- if $?.exitstatus == 0
169
- 'book.pdf'
170
- end
171
- end
172
-
173
37
  def local(file)
174
38
  File.expand_path(File.join(Dir.pwd, file))
175
39
  end
@@ -178,178 +42,20 @@ class GitScribe
178
42
  File.join(SCRIBE_ROOT, file)
179
43
  end
180
44
 
181
- def do_epub
182
- puts "GENERATING EPUB"
183
- # TODO: look for custom stylesheets
184
- `#{a2x_wss('epub')} -v #{BOOK_FILE}`
185
- puts 'exit status', $?.exitstatus
186
- 'book.epub'
187
- end
188
-
189
- def do_html
190
- puts "GENERATING HTML"
191
- # TODO: look for custom stylesheets
192
- #puts `#{a2x_wss('xhtml')} -v #{BOOK_FILE}`
193
- styledir = local('stylesheets')
194
- puts cmd = "asciidoc -a stylesdir=#{styledir} -a theme=handbookish #{BOOK_FILE}"
195
- `#{cmd}`
196
- puts 'exit status', $?.exitstatus
197
- 'book.html'
198
- end
199
-
200
- def do_site
201
- puts "GENERATING SITE"
202
- # TODO: check if html was already done
203
- puts `asciidoc -b docbook #{BOOK_FILE}`
204
- xsldir = base('docbook-xsl/xhtml')
205
- `xsltproc --stringparam html.stylesheet stylesheets/handbookish.css --nonet #{xsldir}/chunk.xsl book.xml`
206
-
207
- source = File.read('index.html')
208
- html = Nokogiri::HTML.parse(source, nil, 'utf-8')
209
-
210
- sections = []
211
- c = -1
212
-
213
- # each chapter
214
- html.css('.toc > dl').each do |section|
215
- section.children.each do |item|
216
- if item.name == 'dt' # section
217
- c += 1
218
- sections[c] ||= {'number' => c}
219
- link = item.css('a').first
220
- sections[c]['title'] = title = link.text
221
- sections[c]['href'] = href = link['href']
222
- clean_title = title.downcase.gsub(/[^a-z0-9\-_]+/, '_') + '.html'
223
- sections[c]['link'] = clean_title
224
- if href[0, 10] == 'index.html'
225
- sections[c]['link'] = 'title.html'
226
- end
227
- sections[c]['sub'] = []
228
- end
229
- if item.name == 'dd' # subsection
230
- item.css('dt').each do |sub|
231
- link = sub.css('a').first
232
- data = {}
233
- data['title'] = title = link.text
234
- data['href'] = href = link['href']
235
- data['link'] = sections[c]['link'] + '#' + href.split('#').last
236
- sections[c]['sub'] << data
237
- end
238
- end
239
- end
240
- puts
241
- end
242
-
243
- pp sections
244
-
245
- book_title = html.css('head > title').text
246
- content = html.css('body > div')[1]
247
- content.css('.toc').first.remove
248
- content = content.inner_html
249
-
250
- puts content
251
- sections.each do |s|
252
- content.gsub!(s['href'], s['link'])
253
- end
254
-
255
- template_dir = File.join(SCRIBE_ROOT, 'site', 'default')
256
-
257
- # copy the template files in
258
- files = Dir.glob(template_dir + '/*')
259
- FileUtils.cp_r files, '.'
260
-
261
- Liquid::Template.file_system = Liquid::LocalFileSystem.new(template_dir)
262
- index_template = Liquid::Template.parse(File.read(File.join(template_dir, 'index.html')))
263
- page_template = Liquid::Template.parse(File.read(File.join(template_dir, 'page.html')))
264
-
265
- # write the index page
266
- main_data = {
267
- 'book_title' => book_title,
268
- 'sections' => sections
269
- }
270
- File.open('index.html', 'w+') do |f|
271
- f.puts index_template.render( main_data )
272
- end
273
-
274
- # write the title page
275
- File.open('title.html', 'w+') do |f|
276
- data = {
277
- 'title' => sections.first['title'],
278
- 'sub' => sections.first['sub'],
279
- 'prev' => {'link' => 'index.html', 'title' => "Main"},
280
- 'home' => {'link' => 'index.html', 'title' => "Home"},
281
- 'next' => sections[1],
282
- 'content' => content
283
- }
284
- data.merge!(main_data)
285
- f.puts page_template.render( data )
286
- end
287
-
288
- # write the other pages
289
- sections.each_with_index do |section, i|
290
-
291
- if i > 0 # skip title page
292
- source = File.read(section['href'])
293
- html = Nokogiri::HTML.parse(source, nil, 'utf-8')
294
-
295
- content = html.css('body > div')[1].to_html
296
- sections.each do |s|
297
- content.gsub!(s['href'], s['link'])
298
- end
299
-
300
- File.open(section['link'], 'w+') do |f|
301
- next_section = nil
302
- if i <= sections.size
303
- next_section = sections[i+1]
304
- end
305
- data = {
306
- 'title' => section['title'],
307
- 'sub' => section['sub'],
308
- 'prev' => sections[i-1],
309
- 'home' => {'link' => 'index.html', 'title' => "Home"},
310
- 'next' => next_section,
311
- 'content' => content
312
- }
313
- data.merge!(main_data)
314
- f.puts page_template.render( data )
315
- end
316
- #File.unlink(section['href'])
317
-
318
- puts i
319
- puts section['title']
320
- puts section['href']
321
- puts section['link']
322
- puts
323
- end
324
-
325
- #File.unlink
326
- end
327
- end
328
-
329
-
330
- # create a new file by concatenating all the ones we find
331
- def gather_and_process
332
- files = Dir.glob("book/*")
333
- FileUtils.cp_r files, 'output'
334
- end
335
-
336
- # DISPLAY HELPER FUNCTIONS #
45
+ # API/DATA HELPER FUNCTIONS #
337
46
 
338
- def l(info, size)
339
- clean(info)[0, size].ljust(size)
47
+ def git(subcommand)
48
+ `git #{subcommand}`.chomp
340
49
  end
341
50
 
342
- def r(info, size)
343
- clean(info)[0, size].rjust(size)
51
+ def first_arg(args)
52
+ Array(args).shift
344
53
  end
345
54
 
346
- def clean(info)
347
- info.to_s.gsub("\n", ' ')
55
+ # eventually we'll want to log this or have it retrievable elsehow
56
+ def info(message)
57
+ @info ||= []
58
+ @info << message
348
59
  end
349
60
 
350
- # API/DATA HELPER FUNCTIONS #
351
-
352
- def git(command)
353
- `git #{command}`.chomp
354
- end
355
61
  end