quiver_note 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +2 -0
- data/lib/quiver.rb +19 -0
- data/lib/quiver/adapter/dropbox.rb +39 -0
- data/lib/quiver/adapter/local.rb +27 -0
- data/lib/quiver/cell.rb +25 -0
- data/lib/quiver/config.rb +28 -0
- data/lib/quiver/note.rb +55 -0
- data/lib/quiver/notebook.rb +34 -0
- data/lib/quiver/root.rb +30 -0
- data/lib/quiver_note.rb +1 -0
- data/lib/quiver_note/version.rb +3 -0
- data/quiver_note.gemspec +25 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 667335961f0426a5143bb8d5da6b3d62f667fd3c
|
4
|
+
data.tar.gz: 87650638ad4621b25cc9f3c5b7215ab367a36fc7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71e7d6964bd2855058b7474a1190fcf67cf1c6e8ea9c22e84d4f387596c7e33c85bb52a0a9e99e76e12c413dc129027dd47f8788a89bd37546eb529452e9992d
|
7
|
+
data.tar.gz: 2478221d4ac4e3053a907006cc401604e1bc05ba08500d8ae305cfe242a7eb8f3db6c2599115b2f244e5db4cf9d1882df9f857ab13ff631ed1abb2120e8c5e45
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 kuboon
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# QuiverNote
|
2
|
+
|
3
|
+
Unofficial ruby interface for [HappenApps quiver](happenapps.com/#quiver)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'quiver'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install quiver
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### example1: Read via dropbox
|
24
|
+
```ruby
|
25
|
+
root = Quiver.dropbox('/Quiver.qvlibrary', dropbox_access_token)
|
26
|
+
inbox = root.nobebook('inbox')
|
27
|
+
inbox.each do |note|
|
28
|
+
puts note.title
|
29
|
+
end
|
30
|
+
```
|
31
|
+
### example2: Write to local storage
|
32
|
+
```ruby
|
33
|
+
root = Quiver.local('/home/kuboon/documents/Quiver.qvlibrary')
|
34
|
+
notebook = root.notebook('blog')
|
35
|
+
|
36
|
+
Entry.find_each do |entry|
|
37
|
+
title = entry.title
|
38
|
+
content = {title: title, cells: [{type: :markdown, data: get_markdown(entry)}]}
|
39
|
+
note = Quiver::Note.new(content: content, meta: {title: title, created_at: entry.created_at.to_i, updated_at: entry.updated_at.to_i})
|
40
|
+
notebook.add(note)
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it ( https://github.com/[my-github-username]/quiver/fork )
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/quiver.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Quiver
|
2
|
+
def self.local(path)
|
3
|
+
adapter = Quiver::Adapter::Local.new(Pathname.new(path))
|
4
|
+
Quiver::Root.new(adapter)
|
5
|
+
end
|
6
|
+
def self.dropbox(path, access_key)
|
7
|
+
adapter = Quiver::Adapter::Dropbox.new(Pathname.new(path), access_key)
|
8
|
+
Quiver::Root.new(adapter)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'quiver_note/version'
|
13
|
+
require 'quiver/config'
|
14
|
+
require 'quiver/root'
|
15
|
+
require 'quiver/notebook'
|
16
|
+
require 'quiver/note'
|
17
|
+
require 'quiver/cell'
|
18
|
+
require 'quiver/adapter/local'
|
19
|
+
require 'quiver/adapter/dropbox'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'dropbox_sdk'
|
2
|
+
module Quiver
|
3
|
+
module Adapter
|
4
|
+
class Dropbox
|
5
|
+
def initialize(root, access_key)
|
6
|
+
@root = root
|
7
|
+
@access_key = access_key
|
8
|
+
end
|
9
|
+
def client
|
10
|
+
@client ||= ::DropboxClient.new(@access_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Don't include this url direct on your site. Use via cdn.
|
14
|
+
def image_url(path)
|
15
|
+
@@image_url_cache ||= {}
|
16
|
+
@@image_url_cache[path] ||= client.media(normalize_path(path))['url']
|
17
|
+
end
|
18
|
+
def each(path)
|
19
|
+
dir_metadata = client.metadata(normalize_path(path))
|
20
|
+
dir_metadata['contents'].each do |content|
|
21
|
+
next unless content['is_dir']
|
22
|
+
yield Pathname.new(content['path'])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
def load(path)
|
26
|
+
client.get_file normalize_path(path)
|
27
|
+
end
|
28
|
+
def save(path, content)
|
29
|
+
client.put_file normalize_path(path), content
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def normalize_path(path)
|
35
|
+
@root.join(path).to_s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Quiver
|
2
|
+
module Adapter
|
3
|
+
class Local
|
4
|
+
def initialize(root)
|
5
|
+
@root = Pathname.new(root)
|
6
|
+
end
|
7
|
+
def image_url(path)
|
8
|
+
"file://" + path.to_s
|
9
|
+
end
|
10
|
+
def each(path, ext)
|
11
|
+
@root.join(path).each_child(false) do |entry|
|
12
|
+
next unless entry.to_s.end_with?(".#{ext}")
|
13
|
+
yield entry
|
14
|
+
end
|
15
|
+
end
|
16
|
+
def load(path)
|
17
|
+
File.read @root.join(path)
|
18
|
+
end
|
19
|
+
def mkpath(path)
|
20
|
+
@root.join(path).mkpath
|
21
|
+
end
|
22
|
+
def save(path, content)
|
23
|
+
@root.join(path).write(content)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/quiver/cell.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Quiver
|
2
|
+
class Cell
|
3
|
+
def initialize(json, note)
|
4
|
+
@note = note
|
5
|
+
@data = json['data']
|
6
|
+
end
|
7
|
+
|
8
|
+
class Text < Cell
|
9
|
+
def to_html
|
10
|
+
"<pre>#{@data}</pre>"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
class Markdown < Cell
|
14
|
+
def initialize(note, json)
|
15
|
+
super
|
16
|
+
@data.gsub!(%r|quiver-image-url/([^)]+)|) do |path|
|
17
|
+
@note.image_url(path)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
def to_html
|
21
|
+
Quiver.config.markdown_renderer.call(@data)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'active_support/configurable'
|
2
|
+
|
3
|
+
module Quiver
|
4
|
+
# Quiver.configure do |config|
|
5
|
+
# config.markdown_renderer = ->(markdown){ MyRenderer.render(markdown) }
|
6
|
+
# end
|
7
|
+
def self.configure(&block)
|
8
|
+
yield @config ||= Quiver::Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
# Global settings for Quiver
|
12
|
+
def self.config
|
13
|
+
@config
|
14
|
+
end
|
15
|
+
|
16
|
+
class Configuration #:nodoc:
|
17
|
+
include ActiveSupport::Configurable
|
18
|
+
config_accessor :markdown_renderer
|
19
|
+
end
|
20
|
+
|
21
|
+
configure do |config|
|
22
|
+
config.markdown_renderer = ->(markdown){
|
23
|
+
raise 'please configure your markdown renderer or add gem "redcarpet".' unless defined? Redcarpet
|
24
|
+
@@redcarpet ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, strikethrough: true, fenced_code_blocks: true, tables: true, autolink: true)
|
25
|
+
@@redcarpet.render(markdown)
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
data/lib/quiver/note.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module Quiver
|
2
|
+
class Note
|
3
|
+
attr_accessor :meta, :path, :notebook
|
4
|
+
def initialize(content: , meta: , path: nil, notebook: nil)
|
5
|
+
@content = content
|
6
|
+
@meta = meta
|
7
|
+
@path = Pathname.new(path) if path
|
8
|
+
@notebook = notebook
|
9
|
+
@adapter = notebook.root.adapter if notebook
|
10
|
+
end
|
11
|
+
def created_at
|
12
|
+
Time.at(meta['created_at'])
|
13
|
+
end
|
14
|
+
def updated_at
|
15
|
+
Time.at(meta['updated_at'])
|
16
|
+
end
|
17
|
+
def title
|
18
|
+
@meta['title']
|
19
|
+
end
|
20
|
+
def uuid
|
21
|
+
@meta['uuid']
|
22
|
+
end
|
23
|
+
def content
|
24
|
+
@content ||= begin
|
25
|
+
JSON.parse(@adapter.load(@path + 'content.json'))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
def cells
|
29
|
+
content['cells'].map do |cell|
|
30
|
+
case cell['type']
|
31
|
+
when 'text'; Quiver::Cell::Text.new(cell, self)
|
32
|
+
when 'markdown'; Quiver::Cell::Markdown.new(cell, self)
|
33
|
+
else Quiver::Cell.new(cell, self)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
def to_html
|
38
|
+
cells.map(&:to_html).join
|
39
|
+
end
|
40
|
+
def image_url(path)
|
41
|
+
rel_path = path.gsub('quiver-image-url/', '')
|
42
|
+
@adapter.image_url(@path + 'resources' + rel_path)
|
43
|
+
end
|
44
|
+
def save
|
45
|
+
raise 'add to notebook first!' unless @path && @adapter
|
46
|
+
adapter.mkpath(@path)
|
47
|
+
adapter.save(@path + 'content.json', @content.to_json) if @content
|
48
|
+
adapter.save(@path + 'meta.json', @meta.to_json)
|
49
|
+
end
|
50
|
+
def as_json(options = nil)
|
51
|
+
return super if options
|
52
|
+
{content: @content, meta: @meta, path: @path.to_s}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Quiver
|
2
|
+
class Notebook
|
3
|
+
attr_reader :meta, :path, :root
|
4
|
+
def initialize(meta:, path: nil, root: nil)
|
5
|
+
@meta = meta
|
6
|
+
@path = Pathname.new(path) if path
|
7
|
+
@root = root
|
8
|
+
@adapter = root.adapter if root
|
9
|
+
end
|
10
|
+
def name
|
11
|
+
@meta['name']
|
12
|
+
end
|
13
|
+
def each(include_content: false)
|
14
|
+
raise 'This notebook has no root' unless @adapter
|
15
|
+
@adapter.each(@path, 'qvnote') do |path|
|
16
|
+
content = JSON.parse(@adapter.load(@path + path + 'content.json')) if include_content
|
17
|
+
meta = JSON.parse(@adapter.load(@path + path + 'meta.json'))
|
18
|
+
yield Note.new(content: content, meta: meta, path: @path + path, notebook: self)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
def save
|
22
|
+
raise 'add to root first!' unless @path && @adapter
|
23
|
+
adapter.mkpath(@path)
|
24
|
+
adapter.save(@path + 'meta.json', @meta.to_json)
|
25
|
+
end
|
26
|
+
def add(note)
|
27
|
+
raise 'this note already added' if note.path
|
28
|
+
note.meta['uuid'] ||= SecureRandom.uuid.upcase
|
29
|
+
note.path = @path + "#{note.meta['uuid']}.qvnote"
|
30
|
+
note.adapter = @adapter
|
31
|
+
note.save
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/quiver/root.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Quiver
|
2
|
+
class Root
|
3
|
+
attr_reader :adapter
|
4
|
+
def initialize(adapter)
|
5
|
+
@adapter = adapter
|
6
|
+
end
|
7
|
+
def each
|
8
|
+
@each_cache = {}
|
9
|
+
@adapter.each('.', 'qvnotebook') do |path|
|
10
|
+
@each_cache[path] ||= begin
|
11
|
+
meta = JSON.parse(@adapter.load(path + 'meta.json'))
|
12
|
+
Notebook.new(meta: meta, path: path, root: self)
|
13
|
+
end
|
14
|
+
yield @each_cache[path]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
def notebook(name)
|
18
|
+
each do |notebook|
|
19
|
+
return notebook if notebook.name == name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
def add(notebook)
|
23
|
+
raise 'this notebook already added' if notebook.path
|
24
|
+
notebook.meta['uuid'] ||= SecureRandom.uuid.upcase
|
25
|
+
notebook.path = @path + "#{notebook.meta['uuid']}.qvnotebook"
|
26
|
+
notebook.adapter = @adapter
|
27
|
+
notebook.save
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/quiver_note.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'quiver'
|
data/quiver_note.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'quiver/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "quiver_note"
|
8
|
+
spec.version = Quiver::VERSION
|
9
|
+
spec.authors = ["kuboon"]
|
10
|
+
spec.email = ["kuboon@trick-with.net"]
|
11
|
+
spec.summary = %q{To manipulate HappenApps Quiver notes.}
|
12
|
+
# spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = "https://github.com/kuboon/quiver"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activesupport", "> 3.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quiver_note
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kuboon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- kuboon@trick-with.net
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/quiver.rb
|
68
|
+
- lib/quiver/adapter/dropbox.rb
|
69
|
+
- lib/quiver/adapter/local.rb
|
70
|
+
- lib/quiver/cell.rb
|
71
|
+
- lib/quiver/config.rb
|
72
|
+
- lib/quiver/note.rb
|
73
|
+
- lib/quiver/notebook.rb
|
74
|
+
- lib/quiver/root.rb
|
75
|
+
- lib/quiver_note.rb
|
76
|
+
- lib/quiver_note/version.rb
|
77
|
+
- quiver_note.gemspec
|
78
|
+
homepage: https://github.com/kuboon/quiver
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.4.5.1
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: To manipulate HappenApps Quiver notes.
|
102
|
+
test_files: []
|