fyodor 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/fyodor/config_getter.rb +9 -6
- data/lib/fyodor/output_generator.rb +4 -25
- data/lib/fyodor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eeecee4acc8d86b2d4e21dc8071d5c1fa29ef5c7a7873f1c8c9cf0a693f2a9fb
|
4
|
+
data.tar.gz: ebd27239fbb6da6fb2fc601ed4138212ded181f135c42c99a4aff45046dcc802
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41bd104a94086a9d42d99b85b99b17105013b38f2fa15f8623af86e64f7b648503748770edbec5d22681700b48f56b577c73c555a2b845f59f0d4b5d0b4590db
|
7
|
+
data.tar.gz: 06575a116669bbd2f1758ef772a5fbb091bfb22381f7cc44315c2f9973a7384174434c8a82443f1dc0ddef934a5f5fc2f49f53cb2caf5f9033897c0449843695
|
data/README.md
CHANGED
@@ -18,7 +18,8 @@ To read more about the motivation and what problem it tries to solve, [check thi
|
|
18
18
|
- Easily configurable for your language, allowing you to get all features and beautiful output.
|
19
19
|
- This software goes some length to be locale agnostic: basic parsing should work without configuration for any language. It should also work even if your clippings file has multiple locales.
|
20
20
|
- Bookmarks are printed together and notes are formatted differently, for better visualization.
|
21
|
-
-
|
21
|
+
- By default, output in a format that is clean and easy to edit/fiddle around: markdown.
|
22
|
+
- Entirely customizable output, through templates, in the format you prefer.
|
22
23
|
|
23
24
|
This program is based on the clippings file generated by Kindle 2019, but should work with other models.
|
24
25
|
|
@@ -80,16 +81,15 @@ In the configuration file you can also set whether to print the time of each ent
|
|
80
81
|
|
81
82
|
### Templating
|
82
83
|
|
83
|
-
|
84
|
+
You may change the structure of the files output by Fyodor by providing your own template.
|
84
85
|
|
85
|
-
|
86
|
-
|
87
|
-
You can find a sample close to the default [here](docs/template.erb.sample). You can use any method or attribute available [at this class](lib/fyodor/output_generator.rb).
|
86
|
+
Simply place a ERB template at `~/.config/fyodor/template.erb` or `$XDG_CONFIG_HOME/fyodor/template.erb` and Fyodor will use it automatically.
|
88
87
|
|
88
|
+
The default template can be found [here](share/template.erb). You can use any method or attribute available [on this class](lib/fyodor/output_generator.rb).
|
89
89
|
|
90
90
|
### Extension
|
91
91
|
|
92
|
-
If you want to change the extension of the output files - typically after changing the template -, set `extension` on fyodor.toml
|
92
|
+
If you want to change the extension of the output files - typically after changing the template -, set `extension` on `fyodor.toml`. For example, to change it to HTML:
|
93
93
|
|
94
94
|
```toml
|
95
95
|
[output]
|
data/lib/fyodor/config_getter.rb
CHANGED
@@ -6,6 +6,7 @@ module Fyodor
|
|
6
6
|
class ConfigGetter
|
7
7
|
CONFIG_NAME = "fyodor.toml"
|
8
8
|
TEMPLATE_NAME = "template.erb"
|
9
|
+
DEFAULT_TEMPLATE_PATH = File.dirname(__FILE__) + "/../../share/template.erb"
|
9
10
|
|
10
11
|
DEFAULTS = {
|
11
12
|
"parser" => {
|
@@ -38,9 +39,7 @@ module Fyodor
|
|
38
39
|
user_config = @config_path.nil? ? {} : TOML.load_file(@config_path)
|
39
40
|
|
40
41
|
config = DEFAULTS.deep_merge(user_config)
|
41
|
-
|
42
|
-
config["output"]["template_path"] = @template_path
|
43
|
-
print_template_path
|
42
|
+
config["output"]["template"] = template
|
44
43
|
|
45
44
|
config
|
46
45
|
end
|
@@ -70,12 +69,16 @@ module Fyodor
|
|
70
69
|
end
|
71
70
|
end
|
72
71
|
|
73
|
-
def
|
74
|
-
|
72
|
+
def template
|
73
|
+
template_path = get_path(TEMPLATE_NAME) || DEFAULT_TEMPLATE_PATH
|
74
|
+
|
75
|
+
if template_path == DEFAULT_TEMPLATE_PATH
|
75
76
|
puts "No template found: using default.\n\n"
|
76
77
|
else
|
77
|
-
puts "Using template at #{
|
78
|
+
puts "Using template at #{template_path}.\n\n"
|
78
79
|
end
|
80
|
+
|
81
|
+
File.read(template_path)
|
79
82
|
end
|
80
83
|
end
|
81
84
|
end
|
@@ -5,39 +5,18 @@ module Fyodor
|
|
5
5
|
class OutputGenerator
|
6
6
|
include Strings
|
7
7
|
|
8
|
-
# The use of <% - 1 %> is a workaround for trimming indentation before <%=.
|
9
|
-
DEFAULT_TEMPLATE = %q{<% -%>
|
10
|
-
<%- 1 %><%= "# #{@book.basename}" %>
|
11
|
-
<% if regular_entries.size > 0 %>
|
12
|
-
<%- 1 %><%= "## Highlights and notes" %>
|
13
|
-
|
14
|
-
<%- 1 %><%= render_entries(regular_entries) %>
|
15
|
-
<% end -%>
|
16
|
-
<% if bookmarks.size > 0 %>
|
17
|
-
<%- 1 %><%= "## Bookmarks" %>
|
18
|
-
|
19
|
-
<%- 1 %><%= render_entries(bookmarks) %>
|
20
|
-
<% end -%>
|
21
|
-
}
|
22
|
-
|
23
8
|
def initialize(book, config)
|
24
9
|
@book = book
|
25
10
|
@config = config
|
26
11
|
end
|
27
12
|
|
28
13
|
def content
|
29
|
-
ERB.new(template, nil, '-').result(binding)
|
14
|
+
ERB.new(@config["template"], nil, '-').result(binding)
|
30
15
|
end
|
31
16
|
|
32
17
|
|
33
18
|
private
|
34
|
-
|
35
|
-
def template
|
36
|
-
return DEFAULT_TEMPLATE if @config["template_path"].to_s.empty?
|
37
|
-
|
38
|
-
File.read(@config["template_path"])
|
39
|
-
end
|
40
|
-
|
19
|
+
|
41
20
|
def regular_entries
|
42
21
|
@book.reject { |entry| entry.type == Entry::TYPE[:bookmark] }
|
43
22
|
end
|
@@ -50,9 +29,9 @@ module Fyodor
|
|
50
29
|
output = ""
|
51
30
|
entries.each do |entry|
|
52
31
|
output += "- #{item_text(entry)}\n\n"
|
53
|
-
output += " #{item_desc(entry)}\n\n"
|
32
|
+
output += " #{item_desc(entry)}\n\n" unless item_desc(entry).empty?
|
54
33
|
end
|
55
|
-
output
|
34
|
+
output.strip
|
56
35
|
end
|
57
36
|
|
58
37
|
def item_text(entry)
|
data/lib/fyodor/version.rb
CHANGED