Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added stats commands

  • Loading branch information...
commit 9e7c7da1a5a1c8b438a98848cbe1ed7792973207 1 parent d4bf08e
Arjan van der Gaag authored
4 Gemfile.lock
@@ -4,7 +4,9 @@ PATH
4 4 rpub (0.2.1)
5 5 builder
6 6 kramdown
  7 + nokogiri
7 8 rubyzip
  9 + textstats
8 10 typogruby
9 11
10 12 GEM
@@ -38,6 +40,7 @@ GEM
38 40 multi_json (~> 1.3)
39 41 simplecov-html (~> 0.5.3)
40 42 simplecov-html (0.5.3)
  43 + textstats (0.0.2)
41 44 thor (0.14.6)
42 45 typogruby (1.0.15)
43 46 rubypants
@@ -50,7 +53,6 @@ DEPENDENCIES
50 53 growl
51 54 guard
52 55 guard-rspec
53   - nokogiri
54 56 rake
55 57 rb-fsevent
56 58 rpub!
3  lib/rpub.rb
@@ -8,6 +8,8 @@
8 8 require 'builder'
9 9 require 'kramdown'
10 10 require 'zip/zip'
  11 +require 'nokogiri'
  12 +require 'textstats'
11 13
12 14 require 'rpub/version'
13 15 require 'rpub/subclass_tracker'
@@ -21,6 +23,7 @@
21 23 require 'rpub/commands/package'
22 24 require 'rpub/commands/help'
23 25 require 'rpub/commands/generate'
  26 +require 'rpub/commands/stats'
24 27 require 'rpub/hash_delegation'
25 28 require 'rpub/book'
26 29 require 'rpub/chapter'
3  lib/rpub/commands/preview.rb
@@ -13,9 +13,8 @@ def initialize(*args)
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(Kramdown::Document.new(concatenation, KRAMDOWN_OPTIONS.merge(:template => layout)).to_html)
  17 + f.write move_styles_inline(concatenated_document.to_html)
19 18 end
20 19 end
21 20
19 lib/rpub/commands/stats.rb
... ... @@ -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
7 lib/rpub/compilation_helpers.rb
@@ -4,6 +4,13 @@ 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 #
3  rpub.gemspec
@@ -40,8 +40,9 @@ 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'
43 45 s.add_development_dependency 'yard'
44   - s.add_development_dependency 'nokogiri'
45 46 s.add_development_dependency 'rspec'
46 47 s.add_development_dependency 'rake'
47 48 s.add_development_dependency 'guard'

0 comments on commit 9e7c7da

Please sign in to comment.
Something went wrong with that request. Please try again.