klipbook 1.0.2 → 2.0.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/CHANGELOG.txt +13 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +17 -6
- data/LICENSE.txt +1 -1
- data/README.md +64 -32
- data/bin/klipbook +45 -9
- data/features/collate.feature +6 -46
- data/features/pretty_print.feature +51 -0
- data/features/step_definitions/collate_steps.rb +8 -52
- data/features/step_definitions/pretty_print_steps.rb +61 -0
- data/klipbook.gemspec +25 -20
- data/lib/klipbook/collate/book_file.rb +54 -0
- data/lib/klipbook/commands/collate.rb +17 -0
- data/lib/klipbook/commands/list_books.rb +19 -0
- data/lib/klipbook/commands/pretty_print.rb +17 -0
- data/lib/klipbook/{output/html_summary_writer.rb → pretty_print/html_printer.rb} +4 -5
- data/lib/klipbook/sources/amazon_site/book_scraper.rb +3 -3
- data/lib/klipbook/sources/book.rb +28 -0
- data/lib/klipbook/{fetcher.rb → sources/book_source.rb} +7 -10
- data/lib/klipbook/sources/clipping.rb +11 -0
- data/lib/klipbook/sources/kindle_device/file.rb +4 -4
- data/lib/klipbook/util/struct_to_json.rb +11 -0
- data/lib/klipbook/version.rb +1 -1
- data/lib/klipbook.rb +13 -10
- data/spec/lib/klipbook/collate/book_file_spec.rb +73 -0
- data/spec/lib/klipbook/{printer_spec.rb → commands/list_books_spec.rb} +5 -5
- data/spec/lib/klipbook/commands/pretty_print_spec.rb +40 -0
- data/spec/lib/klipbook/{output/html_summary_writer_spec.rb → pretty_print/html_printer_spec.rb} +4 -4
- data/spec/lib/klipbook/{fetcher_spec.rb → sources/book_source_spec.rb} +12 -12
- data/spec/lib/klipbook/{book_spec.rb → sources/book_spec.rb} +2 -2
- data/spec/lib/klipbook/sources/kindle_device/file_spec.rb +24 -4
- metadata +24 -19
- data/lib/klipbook/book.rb +0 -18
- data/lib/klipbook/clipping.rb +0 -9
- data/lib/klipbook/collator.rb +0 -17
- data/lib/klipbook/output/book_helpers.rb +0 -12
- data/lib/klipbook/printer.rb +0 -18
- data/spec/lib/klipbook/collator_spec.rb +0 -40
- /data/lib/klipbook/{output → pretty_print}/html_book_summary.erb +0 -0
- /data/lib/klipbook/{invalid_source_error.rb → sources/invalid_source_error.rb} +0 -0
- /data/lib/klipbook/{blank.rb → util/blank.rb} +0 -0
data/CHANGELOG.txt
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
== 2.0.0 / 2013-02-12
|
2
|
+
|
3
|
+
* Feature changes
|
4
|
+
|
5
|
+
* Renamed the collate command to pretty print which describes what it does better.
|
6
|
+
|
7
|
+
* Introduces a _new_ collate command that collates all clippings into a single JSON
|
8
|
+
file.
|
9
|
+
|
10
|
+
* Other unexposed changes
|
11
|
+
|
12
|
+
* Internally refactored much of the codebase into a more sensible structure.
|
13
|
+
|
1
14
|
== 1.0.2 / 2012-12-12
|
2
15
|
|
3
16
|
* Bug fixes
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -9,12 +9,20 @@ GEM
|
|
9
9
|
builder (3.0.0)
|
10
10
|
childprocess (0.3.5)
|
11
11
|
ffi (~> 1.0, >= 1.0.6)
|
12
|
-
coderay (1.0.
|
12
|
+
coderay (1.0.8)
|
13
|
+
columnize (0.3.6)
|
13
14
|
cucumber (1.2.1)
|
14
15
|
builder (>= 2.1.2)
|
15
16
|
diff-lcs (>= 1.1.3)
|
16
17
|
gherkin (~> 2.11.0)
|
17
18
|
json (>= 1.4.6)
|
19
|
+
debugger (1.2.4)
|
20
|
+
columnize (>= 0.3.1)
|
21
|
+
debugger-linecache (~> 1.1.1)
|
22
|
+
debugger-ruby_core_source (~> 1.1.7)
|
23
|
+
debugger-linecache (1.1.2)
|
24
|
+
debugger-ruby_core_source (>= 1.1.1)
|
25
|
+
debugger-ruby_core_source (1.1.8)
|
18
26
|
diff-lcs (1.1.3)
|
19
27
|
domain_name (0.5.6)
|
20
28
|
unf (~> 0.0.3)
|
@@ -48,16 +56,19 @@ GEM
|
|
48
56
|
nokogiri (~> 1.4)
|
49
57
|
ntlm-http (~> 0.1, >= 0.1.1)
|
50
58
|
webrobots (~> 0.0, >= 0.0.9)
|
51
|
-
method_source (0.8)
|
59
|
+
method_source (0.8.1)
|
52
60
|
mime-types (1.19)
|
53
61
|
net-http-digest_auth (1.2.1)
|
54
62
|
net-http-persistent (2.8)
|
55
63
|
nokogiri (1.5.5)
|
56
64
|
ntlm-http (0.1.1)
|
57
|
-
pry (0.9.
|
65
|
+
pry (0.9.11.4)
|
58
66
|
coderay (~> 1.0.5)
|
59
67
|
method_source (~> 0.8)
|
60
|
-
slop (~> 3.
|
68
|
+
slop (~> 3.4)
|
69
|
+
pry-debugger (0.2.1)
|
70
|
+
debugger (~> 1.2.0)
|
71
|
+
pry (~> 0.9.10)
|
61
72
|
rainbow (1.1.4)
|
62
73
|
rake (0.9.2.2)
|
63
74
|
rb-fchange (0.0.5)
|
@@ -75,7 +86,7 @@ GEM
|
|
75
86
|
rspec-expectations (2.7.0)
|
76
87
|
diff-lcs (~> 1.1.2)
|
77
88
|
rspec-mocks (2.7.0)
|
78
|
-
slop (3.
|
89
|
+
slop (3.4.3)
|
79
90
|
terminal-notifier-guard (1.5.3)
|
80
91
|
thor (0.16.0)
|
81
92
|
unf (0.0.5)
|
@@ -96,7 +107,7 @@ DEPENDENCIES
|
|
96
107
|
guard-rspec
|
97
108
|
jeweler (~> 1.6.4)
|
98
109
|
mechanize
|
99
|
-
pry
|
110
|
+
pry-debugger
|
100
111
|
rainbow
|
101
112
|
rcov
|
102
113
|
rr
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,20 +1,23 @@
|
|
1
1
|
# Klipbook
|
2
2
|
|
3
|
-
Klipbook
|
3
|
+
Klipbook takes the highlights and notes that you've created on your Kindle and
|
4
|
+
outputs them into nice html or JSON.
|
4
5
|
|
5
|
-
## An example of a clippings file generated by Klipbook
|
6
|
+
## An example of a html clippings file generated by Klipbook
|
6
7
|
|
7
|
-
<img src="https://github.com/grassdog/klipbook/raw/master/example.png" alt="Example
|
8
|
+
<img src="https://github.com/grassdog/klipbook/raw/master/example.png" alt="Example
|
9
|
+
of a clippings file" />
|
8
10
|
|
9
11
|
## What sources does it support?
|
10
12
|
|
11
13
|
Klipbook can take your highlights from a clippings file off a physical Kindle device
|
12
|
-
or from the [Kindle highlights site](https://kindle.amazon.com/your_highlights)
|
14
|
+
or from the [Kindle highlights site](https://kindle.amazon.com/your_highlights)
|
15
|
+
itself.
|
13
16
|
|
14
17
|
## When should I use the file and when should I use the site?
|
15
18
|
|
16
19
|
If your books are purchased from Amazon directly then use the site. The site is the
|
17
|
-
canonical source and will contain all of your notes and highlights from across all of
|
20
|
+
canonical source and will contain all of your notes and highlights from across all of
|
18
21
|
your Kindle devices and applications. Currently the Amazon highlights site only shows
|
19
22
|
clippings for books you've purchased on Amazon.
|
20
23
|
|
@@ -24,36 +27,43 @@ device only keeps clippings that you made directly on it.
|
|
24
27
|
|
25
28
|
## How does it work?
|
26
29
|
|
27
|
-
Klipbook supports
|
30
|
+
Klipbook supports three commands: `list`, `pprint`, and `collate`.
|
28
31
|
|
29
|
-
###
|
32
|
+
### Pretty print
|
30
33
|
|
31
|
-
`
|
32
|
-
into a
|
34
|
+
`pprint` retrieves the clippings from your latest annotated books and writes them
|
35
|
+
out into a pretty html file for each book.
|
33
36
|
|
34
37
|
#### From a file
|
35
38
|
|
36
|
-
Copy your clippings file (called "My Clippings.txt" on a 3rd generation Kindle) from
|
39
|
+
Copy your clippings file (called "My Clippings.txt" on a 3rd generation Kindle) from
|
40
|
+
your Kindle device to your local drive via USB.
|
37
41
|
|
38
42
|
Then write out a list of your clippings via:
|
39
43
|
|
40
|
-
|
44
|
+
```sh
|
45
|
+
$ klipbook pprint "file:My Clippings.txt"
|
46
|
+
```
|
41
47
|
|
42
|
-
This command will write the collected clippings for the latest annotated book to a
|
43
|
-
directory. You can override the output directory with the
|
48
|
+
This command will write the collected clippings for the latest annotated book to a
|
49
|
+
file in the current directory. You can override the output directory with the
|
50
|
+
`--output-dir` switch.
|
44
51
|
|
45
|
-
You can also specify a maximum count of books you'd like collated with the
|
52
|
+
You can also specify a maximum count of books you'd like collated with the
|
53
|
+
`--num-books` switch.
|
46
54
|
|
47
|
-
Klipbook will not overwrite an exiting file by default. You can change this with
|
48
|
-
|
55
|
+
Klipbook will not overwrite an exiting file by default. You can change this with the
|
56
|
+
`--force` flag.
|
49
57
|
|
50
58
|
#### From the site
|
51
59
|
|
52
60
|
Specify your Amazon username and password to klipbook and it will scrape the site and
|
53
61
|
output a clippings file.
|
54
62
|
|
55
|
-
|
56
|
-
|
63
|
+
```sh
|
64
|
+
$ klipbook pprint site:my-username@blah.com:my-password
|
65
|
+
```
|
66
|
+
|
57
67
|
The same flags above apply.
|
58
68
|
|
59
69
|
Note that the scraping requires a network connection (obviously) and can take a while
|
@@ -61,40 +71,61 @@ so please be patient.
|
|
61
71
|
|
62
72
|
### Set up defaults
|
63
73
|
|
64
|
-
If you don't feel like having your Amazon credentials in your shell history you can
|
65
|
-
default source in the klipbook rc file: `~/.klipbookrc`.
|
74
|
+
If you don't feel like having your Amazon credentials in your shell history you can
|
75
|
+
set your default source in the klipbook rc file: `~/.klipbookrc`.
|
66
76
|
|
67
77
|
This is simply a YAML file and you can specify default values for the source and the
|
68
78
|
output directory, e.g.
|
69
79
|
|
70
|
-
|
71
|
-
|
72
|
-
|
80
|
+
```sh
|
81
|
+
$ cat ~/.klipbookrc
|
82
|
+
|
83
|
+
:source: site:my-username@blah.com:my-password
|
84
|
+
:output: /path/to/my/default/output/directory
|
85
|
+
```
|
73
86
|
|
74
87
|
Command line options override the defaults stored in the rc file.
|
75
88
|
|
76
89
|
### List
|
77
90
|
|
78
|
-
The list command lists the books
|
91
|
+
The `list` command lists the books available in the specified source.
|
79
92
|
|
80
|
-
|
93
|
+
```sh
|
94
|
+
$ klipbook list file:"My Clippings.txt"
|
81
95
|
|
82
|
-
|
83
|
-
|
84
|
-
|
96
|
+
Book list:
|
97
|
+
[1] The Big Sleep by Raymond Chandler
|
98
|
+
[2] How to jump out of a plane without a parachute and survive by Rip Rockjaw
|
99
|
+
```
|
85
100
|
|
86
101
|
By default it will only list the latest book. This can be overrided with the
|
87
102
|
`--num-books` switch.
|
88
103
|
|
104
|
+
### Collate
|
105
|
+
|
106
|
+
`collate` pulls together the clippings from your latest annotated books and combines
|
107
|
+
them into a single JSON file.
|
108
|
+
|
109
|
+
```sh
|
110
|
+
$ klipbook collate -c books.json "file:My Clippings.txt"
|
111
|
+
```
|
112
|
+
|
113
|
+
You can rerun collate on an existing JSON file to add new books. By default existing
|
114
|
+
books in the JSON file will not be overwritten. This can be changed with the `force`
|
115
|
+
flag.
|
116
|
+
|
89
117
|
## Installation
|
90
118
|
|
91
119
|
Klipbook is a Ruby gem. To install simply run:
|
92
120
|
|
93
|
-
|
121
|
+
```sh
|
122
|
+
$ gem install klipbook
|
123
|
+
```
|
94
124
|
|
95
125
|
## Supported Devices
|
96
126
|
|
97
|
-
Klipbook has been tested on clippings files from 3rd generation Kindles and the
|
127
|
+
Klipbook has been tested on clippings files from 3rd generation Kindles and the
|
128
|
+
Kindle Touch.
|
98
129
|
|
99
130
|
## Tested platforms
|
100
131
|
|
@@ -102,9 +133,10 @@ Klipbook has been tested on Mac OSX Mountain Lion using MRI 1.9.3.
|
|
102
133
|
|
103
134
|
## Contributing to Klipbook
|
104
135
|
|
105
|
-
Fork the project on [Github](https://github.com/grassdog/klipbook), add tests for
|
136
|
+
Fork the project on [Github](https://github.com/grassdog/klipbook), add tests for
|
137
|
+
your changes, and submit a well described pull request.
|
106
138
|
|
107
139
|
## Copyright
|
108
140
|
|
109
|
-
Copyright (c)
|
141
|
+
Copyright (c) 2013 Ray Grasso. See LICENSE.txt for further details.
|
110
142
|
|
data/bin/klipbook
CHANGED
@@ -25,32 +25,52 @@ arg_name 'count'
|
|
25
25
|
default_value 1
|
26
26
|
flag [:n, :'num-books']
|
27
27
|
|
28
|
-
desc 'Collate your clippings into a
|
28
|
+
desc 'Collate your clippings into a single json file'
|
29
29
|
arg_name 'source'
|
30
|
-
long_desc "Clippings are fetched from the specified source
|
31
|
-
|
30
|
+
long_desc "Clippings are fetched from the specified source, collated, and written into a single json file.\n\n" +
|
31
|
+
SOURCE_HELP
|
32
32
|
command :collate do |c|
|
33
33
|
|
34
|
-
c.desc '
|
34
|
+
c.desc 'Specify the name of the json file to be written to.'
|
35
|
+
c.arg_name 'File-name'
|
36
|
+
c.flag [:c, :'output-file']
|
37
|
+
|
38
|
+
c.desc 'Force overwrite of any existing book entries within the output file'
|
39
|
+
c.switch [:f, :force]
|
40
|
+
|
41
|
+
c.action do |globals,options,args|
|
42
|
+
book_file_path = output_file(options)
|
43
|
+
books = fetch_books(args, globals)
|
44
|
+
Klipbook::Commands::Collate.new(books, book_file(book_file_path)).call(book_file_path, options[:f])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'Pretty print your clippings into a html file for each book'
|
49
|
+
arg_name 'source'
|
50
|
+
long_desc "Clippings are fetched from the specified source before being written to html " +
|
51
|
+
"files in the output directory.\n\n" + SOURCE_HELP
|
52
|
+
command :pprint do |c|
|
53
|
+
|
54
|
+
c.desc 'Override the directory path where html files are written'
|
35
55
|
c.arg_name 'Directory'
|
36
56
|
c.flag [:o, :'output-dir']
|
37
57
|
|
38
|
-
c.desc 'Force overwrite of any existing
|
58
|
+
c.desc 'Force overwrite of any existing files'
|
39
59
|
c.switch [:f, :force]
|
40
60
|
|
41
61
|
c.action do |globals,options,args|
|
42
62
|
books = fetch_books(args, globals)
|
43
|
-
Klipbook::
|
63
|
+
Klipbook::Commands::PrettyPrint.new(books).call(output_dir(options), options[:f])
|
44
64
|
end
|
45
65
|
end
|
46
66
|
|
47
67
|
desc 'List available books'
|
48
68
|
arg_name 'source'
|
49
|
-
long_desc "
|
69
|
+
long_desc "List the books from the specified source to screen.\n\n" + SOURCE_HELP
|
50
70
|
command :list do |c|
|
51
71
|
c.action do |globals,options,args|
|
52
72
|
books = fetch_books(args, globals)
|
53
|
-
Klipbook::
|
73
|
+
Klipbook::Commands::ListBooks.new(books).call
|
54
74
|
end
|
55
75
|
end
|
56
76
|
|
@@ -75,17 +95,33 @@ on_error do |exception|
|
|
75
95
|
true
|
76
96
|
end
|
77
97
|
|
98
|
+
def book_file(file_path)
|
99
|
+
raw_json = if File.exist?(file_path)
|
100
|
+
File.open(file_path, 'r') do |f|
|
101
|
+
f.read
|
102
|
+
end
|
103
|
+
else
|
104
|
+
''
|
105
|
+
end
|
106
|
+
|
107
|
+
Klipbook::Collate::BookFile.from_json(raw_json)
|
108
|
+
end
|
109
|
+
|
78
110
|
def source_spec(args)
|
79
111
|
@source_spec ||= (args[0] || Klipbook::Config.new.read[:source])
|
80
112
|
end
|
81
113
|
|
82
114
|
def fetch_books(args, globals)
|
83
|
-
Klipbook::
|
115
|
+
Klipbook::Sources::BookSource.new(source_spec(args), globals[:n].to_i).books
|
84
116
|
end
|
85
117
|
|
86
118
|
def output_dir(options)
|
87
119
|
@output_dir ||= (options[:o] || Klipbook::Config.new.read[:output] || Dir.pwd)
|
88
120
|
end
|
89
121
|
|
122
|
+
def output_file(options)
|
123
|
+
@output_file ||= (options[:c] || Klipbook::Config.new.read[:output_file] || File.join(Dir.pwd, 'books.json'))
|
124
|
+
end
|
125
|
+
|
90
126
|
exit run(ARGV)
|
91
127
|
|
data/features/collate.feature
CHANGED
@@ -1,51 +1,11 @@
|
|
1
|
-
Feature: klipbook collates
|
1
|
+
Feature: klipbook collates clippings from a clippings file
|
2
2
|
As an avid reader and note taker
|
3
|
-
I want to see a
|
4
|
-
So that I can
|
3
|
+
I want to see a single JSON file collating the clippings of the books that I've read
|
4
|
+
So that I can export them to other tools for my enjoyment
|
5
5
|
|
6
6
|
Scenario: File with clippings for a book
|
7
|
-
Given a
|
8
|
-
|
9
|
-
|
10
|
-
Then I should find a file in the folder "output" named "Lean Software Development: An Agile Toolkit by Mary Poppendieck and Tom Poppendieck.html" that contains "13" clippings
|
11
|
-
Then I should find a file in the folder "output" named "Instapaper: Long Reads by Instapaper: Long Reads.html" that contains "4" clippings
|
12
|
-
Then I should find a file in the folder "output" named "Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin.html" that contains "3" clippings
|
13
|
-
And the exit status should be 0
|
14
|
-
|
15
|
-
Scenario: Attempting to write to an existing file
|
16
|
-
Given a directory named "output"
|
17
|
-
And a file in "output" named "Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin.html"
|
18
|
-
And a file that contains clippings for 3 books called "input.txt"
|
19
|
-
When I collate clippings for "3" books from the file "input.txt" to the output directory "output"
|
20
|
-
Then the output should contain "Skipping Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin.html"
|
21
|
-
And the exit status should be 0
|
22
|
-
|
23
|
-
Scenario: Force overwrite of an existing file
|
24
|
-
Given a directory named "output"
|
25
|
-
And a file in "output" named "Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin.html"
|
26
|
-
And a file that contains clippings for 3 books called "input.txt"
|
27
|
-
When I collate clippings for "3" books from the file "input.txt" to the output directory "output" forcefully
|
28
|
-
Then the output should contain "Writing Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin.html"
|
29
|
-
And the exit status should be 0
|
30
|
-
|
31
|
-
Scenario: Attempt to write with a bad number of books
|
32
|
-
Given a directory named "output"
|
33
|
-
And a file that contains clippings for 3 books called "input.txt"
|
34
|
-
When I collate clippings for "notanumber" books from the file "input.txt" to the output directory "output"
|
35
|
-
Then the output should contain "error: Specify a number of books greater than 0"
|
36
|
-
And the exit status should be 1
|
37
|
-
|
38
|
-
Scenario: Attempt to write to a non-existent directory
|
39
|
-
Given there is not a directory named "output"
|
40
|
-
And a file that contains clippings for 3 books called "input.txt"
|
41
|
-
When I collate clippings for "3" books from the file "input.txt" to the output directory "output"
|
42
|
-
Then the output should contain "error: Output directory doesn't exist: output"
|
43
|
-
And the exit status should be 1
|
44
|
-
|
45
|
-
@slow
|
46
|
-
Scenario: Site with clippings for a book
|
47
|
-
Given a directory named "output"
|
48
|
-
When I collate clippings for "1" books from the kindle site to the output directory "output"
|
49
|
-
Then I should find "1" collated files containing clippings in the directory "output"
|
7
|
+
Given a file that contains clippings for 3 books called "input.txt"
|
8
|
+
When I collate clippings for "3" books from the file "input.txt" to the output file "books.json"
|
9
|
+
Then I should find a file called "books.json" that contains "Lean Software Development: An Agile Toolkit"
|
50
10
|
And the exit status should be 0
|
51
11
|
|
@@ -0,0 +1,51 @@
|
|
1
|
+
Feature: klipbook pretty prints the clippings from a clippings file
|
2
|
+
As an avid reader and note taker
|
3
|
+
I want to see a pretty html summary for each of the books that I've read
|
4
|
+
So that I can refer to a nice summary of passages I enjoyed in the book
|
5
|
+
|
6
|
+
Scenario: File with clippings for a book
|
7
|
+
Given a directory named "output"
|
8
|
+
And a file that contains clippings for 3 books called "input.txt"
|
9
|
+
When I pretty print clippings for "3" books from the file "input.txt" to the output directory "output"
|
10
|
+
Then I should find a file in the folder "output" named "Lean Software Development: An Agile Toolkit by Mary Poppendieck and Tom Poppendieck.html" that contains "13" clippings
|
11
|
+
Then I should find a file in the folder "output" named "Instapaper: Long Reads by Instapaper: Long Reads.html" that contains "4" clippings
|
12
|
+
Then I should find a file in the folder "output" named "Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin.html" that contains "3" clippings
|
13
|
+
And the exit status should be 0
|
14
|
+
|
15
|
+
Scenario: Attempting to write to an existing file
|
16
|
+
Given a directory named "output"
|
17
|
+
And a file in "output" named "Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin.html"
|
18
|
+
And a file that contains clippings for 3 books called "input.txt"
|
19
|
+
When I pretty print clippings for "3" books from the file "input.txt" to the output directory "output"
|
20
|
+
Then the output should contain "Skipping Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin.html"
|
21
|
+
And the exit status should be 0
|
22
|
+
|
23
|
+
Scenario: Force overwrite of an existing file
|
24
|
+
Given a directory named "output"
|
25
|
+
And a file in "output" named "Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin.html"
|
26
|
+
And a file that contains clippings for 3 books called "input.txt"
|
27
|
+
When I pretty print clippings for "3" books from the file "input.txt" to the output directory "output" forcefully
|
28
|
+
Then the output should contain "Writing Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin.html"
|
29
|
+
And the exit status should be 0
|
30
|
+
|
31
|
+
Scenario: Attempt to write with a bad number of books
|
32
|
+
Given a directory named "output"
|
33
|
+
And a file that contains clippings for 3 books called "input.txt"
|
34
|
+
When I pretty print clippings for "notanumber" books from the file "input.txt" to the output directory "output"
|
35
|
+
Then the output should contain "error: Specify a number of books greater than 0"
|
36
|
+
And the exit status should be 1
|
37
|
+
|
38
|
+
Scenario: Attempt to write to a non-existent directory
|
39
|
+
Given there is not a directory named "output"
|
40
|
+
And a file that contains clippings for 3 books called "input.txt"
|
41
|
+
When I pretty print clippings for "3" books from the file "input.txt" to the output directory "output"
|
42
|
+
Then the output should contain "error: Output directory doesn't exist: output"
|
43
|
+
And the exit status should be 1
|
44
|
+
|
45
|
+
@slow
|
46
|
+
Scenario: Site with clippings for a book
|
47
|
+
Given a directory named "output"
|
48
|
+
When I pretty print clippings for "1" books from the kindle site to the output directory "output"
|
49
|
+
Then I should find "1" pretty formated files containing clippings in the directory "output"
|
50
|
+
And the exit status should be 0
|
51
|
+
|
@@ -1,61 +1,17 @@
|
|
1
|
-
CLIPPING_FILE = File.join(File.dirname(__FILE__), '../fixtures/clippings-for-three-books.txt')
|
2
1
|
|
3
|
-
|
4
|
-
|
2
|
+
When /^I collate clippings for "([^"]*)" books from the file "([^"]*)" to the output file "([^"]*)"$/ do |book_count, input_file, output_file|
|
3
|
+
run_collate(book_count, output_file, input_file)
|
5
4
|
end
|
6
5
|
|
7
|
-
|
6
|
+
Then /^I should find a file called "([^"]*)" that contains "([^"]*)"$/ do |output_file, expected_text|
|
8
7
|
in_current_dir do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
Given /^a file that contains clippings for 3 books called "([^"]*)"$/ do |file_name|
|
14
|
-
in_current_dir { FileUtils.cp(CLIPPING_FILE, file_name) }
|
15
|
-
end
|
16
|
-
|
17
|
-
When /^I collate clippings for "([^"]*)" books from the file "([^"]*)" to the output directory "([^"]*)"$/ do |book_count, input_file, output_dir|
|
18
|
-
run_collate_file(book_count, output_dir, input_file, false)
|
19
|
-
end
|
20
|
-
|
21
|
-
When /^I collate clippings for "([^"]*)" books from the file "([^"]*)" to the output directory "([^"]*)" forcefully$/ do |book_count, input_file, output_dir|
|
22
|
-
run_collate_file(book_count, output_dir, input_file, true)
|
23
|
-
end
|
24
|
-
|
25
|
-
Then /^I should find a file in the folder "([^"]*)" named "([^"]*)" that contains "([^"]*)" clippings$/ do |output_folder, file_name, clipping_count|
|
26
|
-
in_current_dir do
|
27
|
-
file_path = File.join(output_folder, file_name)
|
28
|
-
File.exists?(file_path).should be_true
|
29
|
-
File.open(file_path, 'r') do |f|
|
30
|
-
f.read.should match(/<footer>\s+#{clipping_count} clippings •/m)
|
8
|
+
File.exists?(output_file).should be_true
|
9
|
+
File.open(output_file, 'r') do |f|
|
10
|
+
f.read.should match(/#{expected_text}/m)
|
31
11
|
end
|
32
12
|
end
|
33
13
|
end
|
34
14
|
|
35
|
-
|
36
|
-
|
37
|
-
run_simple(unescape("klipbook -n #{book_count} collate -o #{output_dir}"), false)
|
15
|
+
def run_collate(book_count, output_file, input_file)
|
16
|
+
run_simple(unescape("klipbook -n #{book_count} collate -c #{output_file} file:#{input_file}"), false)
|
38
17
|
end
|
39
|
-
|
40
|
-
Then /^I should find "([^"]*)" collated files containing clippings in the directory "([^"]*)"$/ do |file_count, output_dir|
|
41
|
-
in_current_dir do
|
42
|
-
files = Dir['output/*.html']
|
43
|
-
files.should have(file_count.to_i).items
|
44
|
-
files.each do |fname|
|
45
|
-
File.open(fname, 'r') do |f|
|
46
|
-
f.read.should match(/<footer>\s+\d+ clippings •/m)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def run_collate_file(book_count, output, input, force=false)
|
53
|
-
force_str = if force
|
54
|
-
'-f'
|
55
|
-
else
|
56
|
-
''
|
57
|
-
end
|
58
|
-
|
59
|
-
run_simple(unescape("klipbook -n #{book_count} collate #{force_str} -o #{output} file:#{input}"), false)
|
60
|
-
end
|
61
|
-
|
@@ -0,0 +1,61 @@
|
|
1
|
+
CLIPPING_FILE = File.join(File.dirname(__FILE__), '../fixtures/clippings-for-three-books.txt')
|
2
|
+
|
3
|
+
Given /^a file in "([^"]*)" named "([^"]*)"$/ do |output_dir, file_name|
|
4
|
+
in_current_dir { FileUtils.touch(File.join(output_dir, file_name)) }
|
5
|
+
end
|
6
|
+
|
7
|
+
Given /^there is not a directory named "([^"]*)"$/ do |directory_name|
|
8
|
+
in_current_dir do
|
9
|
+
FileUtils.rm_f(directory_name)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Given /^a file that contains clippings for 3 books called "([^"]*)"$/ do |file_name|
|
14
|
+
in_current_dir { FileUtils.cp(CLIPPING_FILE, file_name) }
|
15
|
+
end
|
16
|
+
|
17
|
+
When /^I pretty print clippings for "([^"]*)" books from the file "([^"]*)" to the output directory "([^"]*)"$/ do |book_count, input_file, output_dir|
|
18
|
+
run_pretty_print_file(book_count, output_dir, input_file, false)
|
19
|
+
end
|
20
|
+
|
21
|
+
When /^I pretty print clippings for "([^"]*)" books from the file "([^"]*)" to the output directory "([^"]*)" forcefully$/ do |book_count, input_file, output_dir|
|
22
|
+
run_pretty_print_file(book_count, output_dir, input_file, true)
|
23
|
+
end
|
24
|
+
|
25
|
+
Then /^I should find a file in the folder "([^"]*)" named "([^"]*)" that contains "([^"]*)" clippings$/ do |output_folder, file_name, clipping_count|
|
26
|
+
in_current_dir do
|
27
|
+
file_path = File.join(output_folder, file_name)
|
28
|
+
File.exists?(file_path).should be_true
|
29
|
+
File.open(file_path, 'r') do |f|
|
30
|
+
f.read.should match(/<footer>\s+#{clipping_count} clippings •/m)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# FIXME This step currently assumes you have site: set up in your klipbookrc
|
36
|
+
When /^I pretty print clippings for "([^"]*)" books from the kindle site to the output directory "([^"]*)"$/ do |book_count, output_dir|
|
37
|
+
run_simple(unescape("klipbook -n #{book_count} pprint -o #{output_dir}"), false)
|
38
|
+
end
|
39
|
+
|
40
|
+
Then /^I should find "([^"]*)" pretty printed files containing clippings in the directory "([^"]*)"$/ do |file_count, output_dir|
|
41
|
+
in_current_dir do
|
42
|
+
files = Dir['output/*.html']
|
43
|
+
files.should have(file_count.to_i).items
|
44
|
+
files.each do |fname|
|
45
|
+
File.open(fname, 'r') do |f|
|
46
|
+
f.read.should match(/<footer>\s+\d+ clippings •/m)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def run_pretty_print_file(book_count, output, input, force=false)
|
53
|
+
force_str = if force
|
54
|
+
'-f'
|
55
|
+
else
|
56
|
+
''
|
57
|
+
end
|
58
|
+
|
59
|
+
run_simple(unescape("klipbook -n #{book_count} pprint #{force_str} -o #{output} file:#{input}"), false)
|
60
|
+
end
|
61
|
+
|