ticard 0.2.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8d5dd81f569aa733193399b6c60108d9dd12c29f
4
+ data.tar.gz: 9063aaae1526992744ab38d91e03e7b63ec56253
5
+ SHA512:
6
+ metadata.gz: babc680ff35a70b9fdf295ed95deb42025a4ed1b7260b59d25dbca4e8de2b893e1ad8b67f8d6a364e33d3ad0628e9b09390954f2a7b8bf3c6704b5b7e384bda6
7
+ data.tar.gz: 8237aa169c695ae13833fd815953c7d21399e60a1a41f2b6cf5fb033fb12ca681380ced09a0f18f6786ec6e0da990e5daa6e5fd4b6e312a3c72a0ba84f43b446
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ticard.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ticard.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Diego Guerra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ # Ticard
2
+
3
+ Easily work with Trello cards from your own text editor:
4
+
5
+ ~~~bash
6
+ $ ticard pull http://trello.com/c/a2343423/my-card
7
+ $ vi a2343423-my-card.md
8
+ ...
9
+ $ ticard push a2343423-my-card.md
10
+ ~~~
11
+
12
+ ## Installation
13
+
14
+ ~~~bash
15
+ $ gem install ticard
16
+ ~~~
17
+
18
+ Ticard needs trello read/write credentials in order to work. Create
19
+ a `.ticard.yml` file in `$HOME` or the directory you'll be working from.
20
+
21
+ ~~~yaml
22
+ keys:
23
+ developer_public_key: 'KEY'
24
+ member_token: 'TOKEN'
25
+ ~~~
26
+
27
+ To get the key and token, follow the steps given in [ruby-trello's
28
+ README](https://github.com/jeremytregunna/ruby-trello#configuration).
29
+
30
+ ## Usage
31
+
32
+ * `ticard pull URL` to download the description of the card to a file
33
+ * `ticard push PATH` to upload the updated description.
34
+
35
+ The file created by `ticard pull` has an html comment with metadata at the
36
+ top, this allows `ticard push` to save and check if modifications have been
37
+ made to the card, so mess with them at your own risk :shit:
38
+
39
+ ## Editor support
40
+
41
+ * [Vim](https://github.com/dgsuarez/vim-ticard)
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( https://github.com/dgsuarez/ticard/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ticard"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,73 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'ticard'
4
+ require 'thor'
5
+ require 'yaml'
6
+
7
+ class TicardCLI < Thor
8
+
9
+ desc "pull CARD-URL", "creates a new file with the card's contents"
10
+ def pull(url)
11
+ card = trello_repo.get(url)
12
+ local_out_repo.put(card)
13
+ end
14
+
15
+ desc "push CARD-FILE", "synchronizes the card's contents in trello"
16
+ option :force
17
+ def push(path=nil)
18
+ local_card = card_from_local_repo(path)
19
+ remote_card = trello_repo.get(local_card.url)
20
+ if options[:force] || local_card.from_same_content_as?(remote_card) || confirm_overwrite
21
+ trello_repo.put(local_card)
22
+ local_out_repo.put(local_card)
23
+ end
24
+ end
25
+
26
+ desc "check CARD-PATH", "checks wether there are any changes in the card"
27
+ def check(path=nil)
28
+ local_card = card_from_local_repo(path)
29
+ remote_card = trello_repo.get(local_card.url)
30
+ unless local_card.from_same_content_as?(remote_card)
31
+ puts "Card has been changed"
32
+ exit 1
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def card_from_local_repo(path)
39
+ local_in_repo = path ? file_repo : piped_repo
40
+ local_in_repo.get(path)
41
+ end
42
+
43
+ def confirm_overwrite
44
+ yes?("Card has been changed since downloaded, save anyway?")
45
+ end
46
+
47
+ def trello_repo
48
+ @_trello_repo ||= Ticard::TrelloRepository.new(trello_credentials)
49
+ end
50
+
51
+ def local_out_repo
52
+ STDOUT.tty? ? file_repo : piped_repo
53
+ end
54
+
55
+ def file_repo
56
+ @_file_repo ||= Ticard::FileRepository.new
57
+ end
58
+
59
+ def piped_repo
60
+ @_piped_repo ||= Ticard::FdRepository.new(STDIN, STDOUT)
61
+ end
62
+
63
+ def trello_credentials
64
+ path = %w(PWD HOME).map { |e| "#{ENV[e]}/.ticard.yml" }.detect { |p| File.exist?(p) }
65
+ YAML.load_file(path)["keys"]
66
+ end
67
+
68
+
69
+ end
70
+
71
+ TicardCLI.start(ARGV)
72
+
73
+
@@ -0,0 +1,15 @@
1
+ require "ticard/version"
2
+ require "ticard/card"
3
+ require "ticard/parser"
4
+ require "ticard/serializer"
5
+
6
+ require "ticard/local_repository"
7
+ require "ticard/file_repository"
8
+ require "ticard/fd_repository"
9
+ require "ticard/trello_repository"
10
+
11
+
12
+ module Ticard
13
+
14
+ # Your code goes here...
15
+ end
@@ -0,0 +1,6 @@
1
+ <!---
2
+ url <%=url%>
3
+ md5 <%=stored_md5%>
4
+ -->
5
+
6
+ <%=content%>
@@ -0,0 +1,28 @@
1
+ require 'digest/md5'
2
+
3
+ module Ticard
4
+ class Card
5
+
6
+ attr_reader :content, :stored_md5, :url
7
+
8
+ def initialize(content, opts={})
9
+ @content = content
10
+ @stored_md5 = opts[:stored_md5]
11
+ @url = opts[:url]
12
+ end
13
+
14
+ def current_md5
15
+ Digest::MD5.hexdigest(@content.strip)
16
+ end
17
+
18
+ def from_same_content_as?(other_card)
19
+ @stored_md5 == other_card.stored_md5
20
+ end
21
+
22
+ def as_stored
23
+ Card.new(@content, :url => @url, :stored_md5 => current_md5)
24
+ end
25
+
26
+ end
27
+ end
28
+
@@ -0,0 +1,20 @@
1
+ module Ticard
2
+ class FdRepository < LocalRepository
3
+
4
+ def initialize(in_fd, out_fd)
5
+ @in_fd = in_fd
6
+ @out_fd = out_fd
7
+ end
8
+
9
+ protected
10
+
11
+ def read(_)
12
+ @in_fd.read
13
+ end
14
+
15
+ def write(_, &b)
16
+ b.call(@out_fd)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ module Ticard
2
+ class FileRepository < LocalRepository
3
+
4
+ protected
5
+
6
+ def path(card)
7
+ regex = /\/c\/(.+?)\/\d*-?(.*?)\/?$/
8
+ match = regex.match(card.url)
9
+ id = match[1]
10
+ name = match[2]
11
+ "#{name}_#{id}.md"
12
+ end
13
+
14
+ def read(card_path)
15
+ File.read(card_path)
16
+ end
17
+
18
+ def write(card, &b)
19
+ File.open(path(card), 'w', &b)
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ module Ticard
2
+ class LocalRepository
3
+
4
+ def get(card_path)
5
+ content = read(card_path)
6
+ Parser.new(content).parse
7
+ end
8
+
9
+ def put(card)
10
+ content = Serializer.new(card.as_stored).serialize
11
+ write(card) { |f| f << content }
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module Ticard
2
+ class Parser
3
+
4
+ def initialize(text)
5
+ @text = text
6
+ end
7
+
8
+ def parse
9
+ Card.new(content, :url => metadata("url"), :stored_md5 => metadata("md5"))
10
+ end
11
+
12
+ def content
13
+ regex = /.*<!---.*?-->[\b\n]*(.*)/m
14
+ regex.match(@text)[1]
15
+ end
16
+
17
+ def metadata(field)
18
+ regex = /.*<!---.*?^\b*#{field} (.+?)$.*-->.+/m
19
+ regex.match(@text)[1]
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require 'erb'
2
+
3
+ module Ticard
4
+ class Serializer
5
+ def initialize(card)
6
+ @card = card
7
+ end
8
+
9
+ def serialize
10
+ erb_path = File.join(File.dirname(File.expand_path(__FILE__)), 'card.md.erb')
11
+ template = ERB.new(File.read(erb_path))
12
+ template.result(@card.instance_eval { binding })
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,34 @@
1
+ require 'trello'
2
+
3
+ module Ticard
4
+ class TrelloRepository
5
+
6
+ def initialize(credentials={})
7
+ Trello.configure do |config|
8
+ config.developer_public_key = credentials["developer_public_key"]
9
+ config.member_token = credentials["member_token"]
10
+ end
11
+ end
12
+
13
+ def get(url)
14
+ in_trello = card_in_trello(url)
15
+ Card.new(in_trello.desc, :url => url).as_stored
16
+ end
17
+
18
+ def put(card)
19
+ in_trello = card_in_trello(card.url)
20
+ in_trello.desc = card.content
21
+ in_trello.save
22
+ end
23
+
24
+ private
25
+
26
+ def card_in_trello(url)
27
+ regex = /\/c\/(.+?)\//
28
+ id = regex.match(url)[1]
29
+ Trello::Card.find(id)
30
+ end
31
+
32
+ end
33
+ end
34
+
@@ -0,0 +1,3 @@
1
+ module Ticard
2
+ VERSION = "0.2.1"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ticard/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ticard"
8
+ spec.version = Ticard::VERSION
9
+ spec.authors = ["Diego Guerra"]
10
+ spec.email = ["diego.guerra.suarez@gmail.com"]
11
+
12
+ spec.summary = %q{Save and sync the contents of Trello cards}
13
+ spec.license = "MIT"
14
+
15
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
16
+ # delete this section to allow pushing this gem to any host.
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'ruby-trello'
24
+ spec.add_dependency 'thor'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.9"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec"
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ticard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Diego Guerra
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-trello
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - diego.guerra.suarez@gmail.com
86
+ executables:
87
+ - ticard
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - exe/ticard
101
+ - lib/ticard.rb
102
+ - lib/ticard/card.md.erb
103
+ - lib/ticard/card.rb
104
+ - lib/ticard/fd_repository.rb
105
+ - lib/ticard/file_repository.rb
106
+ - lib/ticard/local_repository.rb
107
+ - lib/ticard/parser.rb
108
+ - lib/ticard/serializer.rb
109
+ - lib/ticard/trello_repository.rb
110
+ - lib/ticard/version.rb
111
+ - ticard.gemspec
112
+ homepage:
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.5.1
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Save and sync the contents of Trello cards
136
+ test_files: []