unofficial-quiver-export 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c532a92e82c7ad6fc97194afbdcab4b932c810f
4
- data.tar.gz: 855a3a12a4493947aaf85514ac3b0798344b7520
3
+ metadata.gz: 59128619caeb86130d636282cf5d39567d2c51e2
4
+ data.tar.gz: ceaca628cc647f80401d9c4e83aa8889daeb5fa1
5
5
  SHA512:
6
- metadata.gz: 8b4a639dc9f9db7f10f2fcba579cb86614916a3117cad15d41c577ee6f1a84e36fe4bc3e5974ed7677ab53bf4bf58e08055d43b6be85903397c58a47cfdfdb6d
7
- data.tar.gz: 08ad06a10b29e136886153866e82f4fd9ad123c1dbed0f58f7547e5cfb3da160c150fd7e2f18779cf864f9873201bb24b40758bbffe5e82b48b57b4107b06cdc
6
+ metadata.gz: e53439cd3f42062ec81b744d283f0fcfb62a712ef4f8d1f368b8204b7b11efd19af1cb7430da6986d1c5eeb16ee2689f1c43a56e6ba9117de23b8a2f9bb533ca
7
+ data.tar.gz: a0e907ccf35227a63464c762413587a50bae03bdb5597907101eae56f710b3a4812725a293c720fcbdf376cdc491ce06b017902b410981f45f4f27024296b40e
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## 0.0.3 (2015-04-27)
2
+
3
+ Features:
4
+
5
+ - supported incremental updates
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Unofficial Quiver Export
2
2
 
3
- This is the un-official gem for [Quiver](http://happenapps.com/#quiver). It exports plain text files within Quiver notebooks.
3
+ This is the un-official gem for [Quiver](http://happenapps.com/#quiver). It exports Quiver notes to text files.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,12 +8,26 @@ This is the un-official gem for [Quiver](http://happenapps.com/#quiver). It expo
8
8
  gem 'unofficial-quiver-export'
9
9
  ```
10
10
 
11
- ## Warnings
11
+ ## Usage
12
12
 
13
- This gem removes the selected --out option directory. Please back up the directory before execute it.
13
+ ```bash
14
+ quiver-export --in ~/Dropbox/Apps/Quiver/Quiver.qvlibrary --out ~/Dropbox/Apps/Quiver/Quiver.export
15
+ ```
14
16
 
15
- ## Usage
17
+ ## Scheduled task
18
+
19
+ In order to execute scheduled task, you should use `crontab -e`.
20
+
21
+ Example of a setting:
22
+
23
+ ```cron
24
+ LC_CTYPE=en_US.UTF-8
25
+ */5 * * * * $HOME/.rbenv/shims/quiver-export --in $HOME/Dropbox/Apps/Quiver/Quiver.qvlibrary --out $HOME/Dropbox/Apps/Quiver/Quiver.export > $HOME/.quiver-export/quiver-export.log 2>&1
26
+ ```
27
+
28
+ ## For more information
16
29
 
17
30
  ```bash
18
- quiver-export --in ~/Dropbox/App/Quiver/Quiver.qvlibrary --out ~/Dropbox/App/Quiver/Quiver.export --ext .txt
31
+ quiver-export help exec
19
32
  ```
33
+
@@ -5,31 +5,40 @@ module Unofficial
5
5
  module Quiver
6
6
  module Export
7
7
  class CLI < Thor
8
-
9
- desc "exec", "export Quiver notes to .md files."
10
- option :in, required: true
11
- option :out, required: true
12
- option :ext, required: false, default: '.txt'
8
+ desc "exec", "Exports Quiver notes."
9
+ option :in, required: true, desc: 'Quiver working directory.'
10
+ option :out, required: true, desc: 'Directory to export.'
11
+ option :ext, required: false, default: '.txt', desc: 'Extention to export file.'
12
+ option :db, required: false, type: :boolean, default: File.expand_path("~/.quiver-export"), desc: 'DB file path.'
13
+ option :log, required: false, bunner: '<PATH>', desc: 'Log file path. If it is not specified, the default is stdout.'
14
+ option :clean, required: false, type: :boolean, default: false, desc: 'Removes --out directory before execute.'
15
+ option :debug, required: false, type: :boolean, default: false, desc: 'Prints debug logs.'
13
16
  default_task :exec
14
17
 
15
18
  def exec
16
- puts "options: in = #{options[:in]}, out = #{options[:out]}"
19
+ init
20
+
21
+ Logger.debug("options: #{options}")
17
22
 
18
- clean
19
23
  scan_content do |content_file|
20
24
  writer = NoteWriter.new(content_file, options)
21
25
  writer.write
22
26
  end
23
27
 
24
- puts 'Export complete!!'
28
+ Logger.info('Export complete!!')
25
29
  end
26
30
 
27
31
  private
28
32
 
33
+ def init
34
+ Logger.configure(options[:log], debug: options[:debug])
35
+ clean if options[:clean]
36
+ end
37
+
29
38
  def clean
30
- puts 'Clean the --out option directory.'
31
- d = options[:out]
32
- FileUtils.rm_r(d) if File.exists?(d)
39
+ Logger.info('Clean --out and --db option directories.')
40
+ FileUtils.rm_r(options[:out]) if File.exists?(options[:out])
41
+ FileUtils.rm_r(options[:db]) if File.exists?(options[:db])
33
42
  end
34
43
 
35
44
  def scan_content
@@ -0,0 +1,41 @@
1
+ require 'logger'
2
+
3
+ module Unofficial
4
+ module Quiver
5
+ module Export
6
+ class Logger
7
+ def self.configure(out, debug: false)
8
+ init_instance(out)
9
+
10
+ @logger.level = ::Logger::INFO unless debug
11
+ end
12
+
13
+ def self.debug(msg)
14
+ @logger.debug(msg)
15
+ end
16
+
17
+ def self.info(msg)
18
+ @logger.info(msg)
19
+ end
20
+
21
+ def self.warn(msg)
22
+ @logger.warn(msg)
23
+ end
24
+
25
+ def self.error(msg)
26
+ @logger.error(msg)
27
+ end
28
+
29
+ private
30
+
31
+ def self.init_instance(out)
32
+ if out.nil?
33
+ @logger = ::Logger.new(STDOUT)
34
+ else
35
+ @logger = ::Logger.new(out)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,35 +1,55 @@
1
+ require 'moneta'
2
+
1
3
  module Unofficial
2
4
  module Quiver
3
5
  module Export
4
6
  class NoteWriter
5
7
  def initialize(content_file, options)
6
- @content_file = content_file
8
+ @content_file = File.new(content_file)
7
9
  @content = JSON.parse(open(content_file).read)
8
10
  @options = options
11
+
12
+ @store = Moneta.new(:HashFile, dir: @options[:db])
9
13
  end
10
14
 
11
15
  def write
16
+ return unless updated?
17
+
12
18
  open(output_note_file, 'w') do |f|
13
- puts f.path
19
+ Logger.debug(f.path)
14
20
  @content['cells'].each do |cell|
15
21
  f.puts cell['data']
16
22
  end
17
23
  end
24
+
25
+ save_last_updated_time
18
26
  end
19
27
 
20
28
  private
21
29
 
22
- def meta_file
23
- @meta_file ||= File.join(File.dirname(@content_file), '../meta.json')
30
+ def updated?
31
+ wrote_time = @store[meta['uuid']]
32
+ return true unless wrote_time
33
+
34
+ wrote_time < @content_file.mtime
35
+ end
36
+
37
+ def save_last_updated_time
38
+ @store[meta['uuid']] = @content_file.mtime
39
+ end
40
+
41
+ def meta
42
+ f = File.join(File.dirname(@content_file), 'meta.json')
43
+ @meta = JSON.parse(open(f).read)
24
44
  end
25
45
 
26
- def nootbook
27
- nootbook_meta = JSON.parse(open(meta_file).read)
28
- nootbook_meta['name']
46
+ def notebook_meta
47
+ f = File.join(File.dirname(@content_file), '../meta.json')
48
+ @notebook_meta = JSON.parse(open(f).read)
29
49
  end
30
50
 
31
51
  def output_note_file
32
- f = File.join(@options[:out], nootbook, @content['title'].gsub('/', '') + @options[:ext])
52
+ f = File.join(@options[:out], notebook_meta['name'], @content['title'].gsub('/', '') + @options[:ext])
33
53
  FileUtils.mkdir_p(File.dirname(f))
34
54
  f
35
55
  end
@@ -1,7 +1,7 @@
1
1
  module Unofficial
2
2
  module Quiver
3
3
  module Export
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
7
7
  end
@@ -1,3 +1,4 @@
1
1
  require "unofficial/quiver/export/version"
2
+ require "unofficial/quiver/export/logger"
2
3
  require "unofficial/quiver/export/note_writer"
3
4
  require "unofficial/quiver/export/cli"
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib"]
22
22
 
23
23
  spec.add_runtime_dependency "thor"
24
+ spec.add_runtime_dependency "moneta"
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.9"
26
27
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unofficial-quiver-export
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Norimitsu YAMASHITA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-26 00:00:00.000000000 Z
11
+ date: 2015-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: moneta
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -78,6 +92,7 @@ files:
78
92
  - ".gitignore"
79
93
  - ".rspec"
80
94
  - ".travis.yml"
95
+ - CHANGELOG.md
81
96
  - Gemfile
82
97
  - README.md
83
98
  - Rakefile
@@ -86,6 +101,7 @@ files:
86
101
  - exe/quiver-export
87
102
  - lib/unofficial/quiver/export.rb
88
103
  - lib/unofficial/quiver/export/cli.rb
104
+ - lib/unofficial/quiver/export/logger.rb
89
105
  - lib/unofficial/quiver/export/note_writer.rb
90
106
  - lib/unofficial/quiver/export/version.rb
91
107
  - unofficial-quiver-export.gemspec