rpub 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +2 -0
- data/Gemfile.lock +6 -3
- data/HISTORY.md +7 -0
- data/lib/rpub.rb +4 -0
- data/lib/rpub/book.rb +7 -5
- data/lib/rpub/chapter.rb +1 -1
- data/lib/rpub/commands/preview.rb +1 -2
- data/lib/rpub/commands/stats.rb +19 -0
- data/lib/rpub/compilation_helpers.rb +12 -1
- data/lib/rpub/version.rb +1 -1
- data/rpub.gemspec +3 -1
- data/spec/fixtures/no_files/config.yml +1 -0
- data/spec/rpub/book_spec.rb +5 -9
- data/spec/spec_helper.rb +1 -1
- metadata +41 -8
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rpub (0.
|
4
|
+
rpub (0.3.0)
|
5
5
|
builder
|
6
6
|
kramdown
|
7
|
+
nokogiri
|
7
8
|
rubyzip
|
9
|
+
textstats
|
10
|
+
typogruby
|
8
11
|
typogruby
|
9
12
|
|
10
13
|
GEM
|
@@ -33,11 +36,12 @@ GEM
|
|
33
36
|
diff-lcs (~> 1.1.3)
|
34
37
|
rspec-mocks (2.9.0)
|
35
38
|
rubypants (0.2.0)
|
36
|
-
rubyzip (0.9.
|
39
|
+
rubyzip (0.9.8)
|
37
40
|
simplecov (0.6.2)
|
38
41
|
multi_json (~> 1.3)
|
39
42
|
simplecov-html (~> 0.5.3)
|
40
43
|
simplecov-html (0.5.3)
|
44
|
+
textstats (0.0.2)
|
41
45
|
thor (0.14.6)
|
42
46
|
typogruby (1.0.15)
|
43
47
|
rubypants
|
@@ -50,7 +54,6 @@ DEPENDENCIES
|
|
50
54
|
growl
|
51
55
|
guard
|
52
56
|
guard-rspec
|
53
|
-
nokogiri
|
54
57
|
rake
|
55
58
|
rb-fsevent
|
56
59
|
rpub!
|
data/HISTORY.md
CHANGED
data/lib/rpub.rb
CHANGED
@@ -8,6 +8,9 @@ require 'erb'
|
|
8
8
|
require 'builder'
|
9
9
|
require 'kramdown'
|
10
10
|
require 'zip/zip'
|
11
|
+
require 'nokogiri'
|
12
|
+
require 'textstats'
|
13
|
+
require 'typogruby'
|
11
14
|
|
12
15
|
require 'rpub/version'
|
13
16
|
require 'rpub/subclass_tracker'
|
@@ -21,6 +24,7 @@ require 'rpub/commands/preview'
|
|
21
24
|
require 'rpub/commands/package'
|
22
25
|
require 'rpub/commands/help'
|
23
26
|
require 'rpub/commands/generate'
|
27
|
+
require 'rpub/commands/stats'
|
24
28
|
require 'rpub/hash_delegation'
|
25
29
|
require 'rpub/book'
|
26
30
|
require 'rpub/chapter'
|
data/lib/rpub/book.rb
CHANGED
@@ -11,14 +11,17 @@ module Rpub
|
|
11
11
|
# @return [Hash] The hash of configuration options read from the config.yml file.
|
12
12
|
attr_reader :config
|
13
13
|
|
14
|
-
# @return [Array] List of chapters, one for every input markdown file.
|
14
|
+
# @return [Array<Chapter>] List of chapters, one for every input markdown file.
|
15
15
|
attr_reader :chapters
|
16
16
|
|
17
|
+
# @return [Array<String>] all the fonts referred to in the stylesheet
|
18
|
+
attr_reader :fonts
|
19
|
+
|
17
20
|
# @return [String] the path the layout HTML file to use to wrap the chapter in.
|
18
21
|
attr_reader :layout
|
19
22
|
|
20
|
-
def initialize(layout, config = {})
|
21
|
-
@chapters, @config, @layout = [], config, layout
|
23
|
+
def initialize(layout, config = {}, fonts = [])
|
24
|
+
@chapters, @config, @layout, @fonts = [], config, layout, fonts
|
22
25
|
end
|
23
26
|
|
24
27
|
def each(&block)
|
@@ -26,8 +29,7 @@ module Rpub
|
|
26
29
|
end
|
27
30
|
|
28
31
|
def has_fonts?
|
29
|
-
fonts
|
30
|
-
fonts.respond_to?(:any?) && fonts.any?
|
32
|
+
fonts.any?
|
31
33
|
end
|
32
34
|
|
33
35
|
def has_toc?
|
data/lib/rpub/chapter.rb
CHANGED
@@ -30,7 +30,7 @@ module Rpub
|
|
30
30
|
|
31
31
|
# @return [String] content parsed to HTML by the markdown engine.
|
32
32
|
def to_html
|
33
|
-
@to_html ||= @document.to_html
|
33
|
+
@to_html ||= Typogruby.improve(@document.to_html)
|
34
34
|
end
|
35
35
|
|
36
36
|
# @return [String] name for the file in the zip to use, based on the title
|
@@ -13,9 +13,8 @@ module Rpub
|
|
13
13
|
def invoke
|
14
14
|
super
|
15
15
|
return unless markdown_files.any?
|
16
|
-
concatenation = markdown_files.join("\n")
|
17
16
|
File.open(@filename, 'w') do |f|
|
18
|
-
f.write move_styles_inline(
|
17
|
+
f.write move_styles_inline(Typogruby.improve(concatenated_document.to_html))
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Rpub
|
2
|
+
module Commands
|
3
|
+
class Stats < Base
|
4
|
+
identifier 'stats'
|
5
|
+
include CompilationHelpers
|
6
|
+
|
7
|
+
def invoke
|
8
|
+
super
|
9
|
+
text = Nokogiri::HTML(concatenated_document.to_html).xpath('//text()').to_s
|
10
|
+
puts "#{text.words.size} words"
|
11
|
+
puts "#{text.words.size / 500} pages"
|
12
|
+
puts "#{text.sentences} sentences"
|
13
|
+
puts "#{text.avg_sentence_length} avg sentence length"
|
14
|
+
puts "#{text.ari} ari"
|
15
|
+
puts "#{text.clf} clf"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -4,13 +4,20 @@ module Rpub
|
|
4
4
|
# from the current project directory.
|
5
5
|
module CompilationHelpers
|
6
6
|
|
7
|
+
def concatenated_document
|
8
|
+
Kramdown::Document.new(
|
9
|
+
markdown_files.join("\n"),
|
10
|
+
KRAMDOWN_OPTIONS.merge(:template => layout)
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
7
14
|
# Factory method for {Rpub::Book} objects, loading every markdown file as a
|
8
15
|
# chapter.
|
9
16
|
#
|
10
17
|
# @see #markdown_files
|
11
18
|
# @return [Rpub::Book]
|
12
19
|
def create_book
|
13
|
-
book = Book.new(layout, config)
|
20
|
+
book = Book.new(layout, config, fonts)
|
14
21
|
markdown_files.each(&book.method(:<<))
|
15
22
|
book
|
16
23
|
end
|
@@ -46,6 +53,10 @@ module Rpub
|
|
46
53
|
|
47
54
|
private
|
48
55
|
|
56
|
+
def fonts
|
57
|
+
@fonts ||= File.read(styles).scan(/url\((?:'|")?([^'")]+\.otf)(?:'|")?\)/i).flatten
|
58
|
+
end
|
59
|
+
|
49
60
|
def filter_exceptions(filenames)
|
50
61
|
return filenames unless config.has_key?('ignore')
|
51
62
|
filenames.reject(&config['ignore'].method(:include?))
|
data/lib/rpub/version.rb
CHANGED
data/rpub.gemspec
CHANGED
@@ -40,8 +40,10 @@ EOS
|
|
40
40
|
s.add_runtime_dependency 'kramdown'
|
41
41
|
s.add_runtime_dependency 'rubyzip'
|
42
42
|
s.add_runtime_dependency 'builder'
|
43
|
+
s.add_runtime_dependency 'nokogiri'
|
44
|
+
s.add_runtime_dependency 'textstats'
|
45
|
+
s.add_runtime_dependency 'typogruby'
|
43
46
|
s.add_development_dependency 'yard'
|
44
|
-
s.add_development_dependency 'nokogiri'
|
45
47
|
s.add_development_dependency 'rspec'
|
46
48
|
s.add_development_dependency 'rake'
|
47
49
|
s.add_development_dependency 'guard'
|
@@ -0,0 +1 @@
|
|
1
|
+
---
|
data/spec/rpub/book_spec.rb
CHANGED
@@ -35,20 +35,16 @@ describe Rpub::Book do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
describe '#has_fonts?' do
|
38
|
-
it 'should not have a font
|
38
|
+
it 'should not have a font by default' do
|
39
39
|
described_class.new(nil, {}).should_not have_fonts
|
40
40
|
end
|
41
41
|
|
42
|
-
it 'should not have a font with
|
43
|
-
described_class.new(nil,
|
42
|
+
it 'should not have a font with an empty array' do
|
43
|
+
described_class.new(nil, nil, []).should_not have_fonts
|
44
44
|
end
|
45
45
|
|
46
|
-
it 'should
|
47
|
-
described_class.new(nil,
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'should have a font with a non-empty config key' do
|
51
|
-
described_class.new(nil, { 'fonts' => ['foo']}).should have_fonts
|
46
|
+
it 'should have a font with a non-empty array' do
|
47
|
+
described_class.new(nil, nil, ['foo']).should have_fonts
|
52
48
|
end
|
53
49
|
end
|
54
50
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: typogruby
|
@@ -76,14 +76,14 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: nokogiri
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
83
|
- - ! '>='
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
|
-
type: :
|
86
|
+
type: :runtime
|
87
87
|
prerelease: false
|
88
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
89
|
none: false
|
@@ -92,7 +92,39 @@ dependencies:
|
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
95
|
+
name: textstats
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: typogruby
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: yard
|
96
128
|
requirement: !ruby/object:Gem::Requirement
|
97
129
|
none: false
|
98
130
|
requirements:
|
@@ -261,6 +293,7 @@ files:
|
|
261
293
|
- lib/rpub/commands/main.rb
|
262
294
|
- lib/rpub/commands/package.rb
|
263
295
|
- lib/rpub/commands/preview.rb
|
296
|
+
- lib/rpub/commands/stats.rb
|
264
297
|
- lib/rpub/compilation_helpers.rb
|
265
298
|
- lib/rpub/compressor.rb
|
266
299
|
- lib/rpub/epub.rb
|
@@ -316,7 +349,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
316
349
|
version: '0'
|
317
350
|
segments:
|
318
351
|
- 0
|
319
|
-
hash:
|
352
|
+
hash: 883141922978996594
|
320
353
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
321
354
|
none: false
|
322
355
|
requirements:
|
@@ -325,10 +358,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
325
358
|
version: '0'
|
326
359
|
segments:
|
327
360
|
- 0
|
328
|
-
hash:
|
361
|
+
hash: 883141922978996594
|
329
362
|
requirements: []
|
330
363
|
rubyforge_project:
|
331
|
-
rubygems_version: 1.8.
|
364
|
+
rubygems_version: 1.8.23
|
332
365
|
signing_key:
|
333
366
|
specification_version: 3
|
334
367
|
summary: ! 'rPub is a command-line tool that generates a collection of plain text
|