jottit-to 0.1.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: 3eb04a78b605f24f64425524bd0e08a65618ac85
4
+ data.tar.gz: e3d4bd1c345cd252e843be58937f048859820ee5
5
+ SHA512:
6
+ metadata.gz: 06929391f3825c3e5c550a6580a4d9244534e0ee17b3d19a1ce2fbc0024f9f8f4d93132a6db43cb081aa98b810c07bd149def509d85cd62ce66fa20d822f73f8
7
+ data.tar.gz: 65d1eb1d1b82e01ee760b3ab471076d9017b7b8a3b8564534549626dd5b20fc762ffe7c713b67eaa58ff975082fc70ab634e48c36790af522e3deebea3eea380
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jottit-to.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 toooooooby
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.
@@ -0,0 +1,75 @@
1
+ # JottitTo
2
+
3
+ Jottit list page converter for CLI
4
+
5
+ ## Installation
6
+
7
+ $ gem install jottit-to
8
+
9
+ ## Usage
10
+
11
+ As a tool for CLI:
12
+
13
+ ```bash
14
+ $ jottit-to json http://youpy.jottit.com/trivia
15
+ ["Evernoteは象で動いている","CD音質を超えるデータはすべてハイレゾ", ...
16
+
17
+ $ jottit-to yaml http://youpy.jottit.com/trivia | head
18
+ ---
19
+ - Evernoteは象で動いている
20
+ - CD音質を超えるデータはすべてハイレゾ
21
+ :
22
+
23
+ $ jottit-to text http://youpy.jottit.com/trivia | head
24
+ Evernoteは象で動いている
25
+ CD音質を超えるデータはすべてハイレゾ
26
+ :
27
+
28
+ $ jottit-to xml http://youpy.jottit.com/trivia | head
29
+ <?xml version="1.0" encoding="UTF-8"?>
30
+ <items>
31
+ <item>Evernoteは象で動いている</item>
32
+ <item>CD音質を超えるデータはすべてハイレゾ</item>
33
+ :
34
+ ```
35
+
36
+ Applications for CLI:
37
+
38
+
39
+ * Fetch random one
40
+
41
+ ```bash
42
+ $ jottit-to text http://youpy.jottit.com/trivia | shuf -n 1
43
+ 高性能な機械は触ると少しひんやりする
44
+ ```
45
+ * Tweet a trivia with usging `tw` gem ( http://shokai.github.io/tw/ )
46
+
47
+ ```bash
48
+ $ jottit-to text http://youpy.jottit.com/trivia | shuf -n 1 | tw --pipe
49
+ 首をボキボキ鳴らすと1トンの衝撃がかかる
50
+ http://twitter.com/toby_net/status/451337693436198913
51
+ 2014-04-02 21:37:46 +0900
52
+ ```
53
+
54
+ * Tweet a trivia like yazawa using `YAZAWA` gem ( https://github.com/toooooooby/yazawa ) and tw
55
+
56
+ ```bash
57
+ $ jottit-to text http://youpy.jottit.com/trivia | shuf -n 1 | yazawa | tw --pipe
58
+ 『SOUJI』は人を裏切らない
59
+ http://twitter.com/toby_net/status/451338808189911040
60
+ 2014-04-02 21:42:12 +0900
61
+ ```
62
+
63
+ As a library of ruby:
64
+
65
+ ```ruby
66
+ require 'jottit-to'
67
+
68
+ uri = 'http://youpy.jottit.com/trivia'
69
+
70
+ puts JottitTo.parse_uri(uri).to_json # Fetch and print as JSON
71
+ puts JottitTo.parse_uri(uri).to_yaml # Fetch and print as yaml
72
+ puts JottitTo.parse_uri(uri).to_text # Fetch and print as text
73
+ puts JottitTo.parse_uri(uri).to_xml # Fetch and print as xml
74
+ ```
75
+
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task default: :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.test_files = FileList['test/test_*.rb']
8
+ t.verbose = true
9
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/jottit-to'
4
+ JottitTo::CLI.start
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jottit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jottit-to"
8
+ spec.version = JottitTo::VERSION
9
+ spec.authors = ["toooooooby"]
10
+ spec.email = ["toby.net.info.mail+git@gmail.com"]
11
+ spec.summary = %q{Jottit list page converter CLI}
12
+ spec.description = %q{A tool for converting a list in jottit page to any formats}
13
+ spec.homepage = "https://github.com/toooooooby/jottit-to"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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 'thor', '~> 0.19'
22
+ spec.add_dependency 'nokogiri', '~> 1.6'
23
+ spec.add_dependency 'builder', '~> 3.2'
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency 'rake', '~> 10.2'
26
+ spec.add_development_dependency 'webmock', '~> 1.17'
27
+ end
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require 'thor'
4
+ require 'nokogiri'
5
+ require 'open-uri'
6
+ require 'json'
7
+ require 'yaml'
8
+ require 'builder'
9
+
10
+ module JottitTo
11
+ class CLI < Thor
12
+ map '-t' => :text, '-j' => :json, '-y' => :yaml, 'yml' => :yaml
13
+
14
+ desc 'text URI', 'Show as text'
15
+ def text(uri)
16
+ puts JottitTo.parse_uri(uri).to_a
17
+ end
18
+
19
+ desc 'json URI', 'Show as json'
20
+ def json(uri)
21
+ puts JottitTo.parse_uri(uri).to_json
22
+ end
23
+
24
+ desc 'yaml URI', 'Show as yaml'
25
+ def yaml(uri)
26
+ puts JottitTo.parse_uri(uri).to_yaml
27
+ end
28
+
29
+ desc 'xml URI', 'Show as xml'
30
+ def xml(uri)
31
+ puts JottitTo.parse_uri(uri).to_xml
32
+ end
33
+
34
+ desc 'version', 'Show version'
35
+ map '-v' => :version
36
+ def version
37
+ require_relative './jottit/version'
38
+ say "Jottit-to #{JottitTo::VERSION}"
39
+ end
40
+ end
41
+
42
+
43
+ class << self
44
+ # e.g. http://youpy.jottit.com/trivia?m=diff&r=525&r=526#fuba =>
45
+ # http://youpy.jottit.com/trivia
46
+ def normalize_uri(src)
47
+ uri = URI(src)
48
+ uri.query = nil
49
+ uri.fragment = nil
50
+ uri.to_s
51
+ end
52
+
53
+ # e.g. <div id="content"><ul><li>foo</li><li>bar</li><ul></div> =>
54
+ # ['foo', 'bar']
55
+ def parse_html(html)
56
+ html = Nokogiri::HTML(html)
57
+ items = html.css('#content>ul>li').map(&:text)
58
+ items.extend JottitTo::ArrayExtender
59
+ items
60
+ end
61
+
62
+ # e.g. http://youpy.jottit.com/trivia => ['foo', 'bar']
63
+ def parse_uri(uri)
64
+ html = URI(normalize_uri(uri)).read
65
+ parse_html(html)
66
+ end
67
+ end
68
+
69
+ module ArrayExtender
70
+ # e.g. self => "foo\nbar\n"
71
+ def to_text
72
+ self.join("\n")
73
+ end
74
+
75
+ # e.g. self => "<?xml version="1.0" encoding="UTF-8"?>
76
+ # <items>
77
+ # <item>foo</item>
78
+ # <item>bar</item>
79
+ # </items>"
80
+ def to_xml
81
+ builder = Builder::XmlMarkup.new(:indent=>2)
82
+ builder.instruct! :xml, version: '1.0', encoding: 'UTF-8'
83
+ xml = builder.items{ self.each{|x| builder.item(x) } }
84
+ xml
85
+ end
86
+ end
87
+ end
88
+
89
+
@@ -0,0 +1,3 @@
1
+ module JottitTo
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,29 @@
1
+ - src: [foo, bar, buzz, piyo]
2
+ expected_as_xml: |
3
+ <?xml version="1.0" encoding="UTF-8"?>
4
+ <items>
5
+ <item>foo</item>
6
+ <item>bar</item>
7
+ <item>buzz</item>
8
+ <item>piyo</item>
9
+ </items>
10
+ expected_as_text: |-
11
+ foo
12
+ bar
13
+ buzz
14
+ piyo
15
+ expected_as_json: '["foo","bar","buzz","piyo"]'
16
+ expected_as_yaml: |
17
+ ---
18
+ - foo
19
+ - bar
20
+ - buzz
21
+ - piyo
22
+ - src: []
23
+ expected_as_xml: |
24
+ <?xml version="1.0" encoding="UTF-8"?>
25
+ <items>
26
+ </items>
27
+ expected_as_text: ''
28
+ expected_as_json: '[]'
29
+ expected_as_yaml: "--- []\n"
@@ -0,0 +1,54 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
4
+ <head>
5
+ <title> trivia</title>
6
+
7
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
+ <link rel="shortcut icon" href="/favicon.ico" />
9
+ <link rel="stylesheet" type="text/css" media="screen, projection" href="/static/css-generated.css?1384544135" />
10
+
11
+ </head>
12
+
13
+ <body class="app">
14
+
15
+ <div id="wrapper">
16
+
17
+
18
+ <div id="content_wrapper">
19
+ <div id="content">
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+ <ul>
30
+ <li>foo</li>
31
+ <li>bar</li>
32
+ <li>buzz</li>
33
+ <li>piyo</li>
34
+ </ul>
35
+
36
+
37
+
38
+ <div id="dateline">
39
+ </div>
40
+
41
+
42
+ </div> <!-- end #content -->
43
+ <div id="footer">
44
+ </div>
45
+ </div> <!-- end #content_wrapper -->
46
+
47
+ <div id="sidebar">
48
+ </div> <!-- end #sidebar -->
49
+ </div> <!-- end #wrapper -->
50
+
51
+
52
+
53
+ </body>
54
+ </html>
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require 'minitest/autorun'
4
+
5
+ # For colorful testing
6
+ begin
7
+ require 'minitest/pride'
8
+ rescue LoadError
9
+ # Ignore an error for old ruby
10
+ end if $stdout.isatty
11
+
12
+ require 'webmock/minitest'
13
+ require 'yaml'
14
+
15
+ require_relative '../lib/jottit-to'
16
+
17
+ describe JottitTo do
18
+ it 'can get normalized uri' do
19
+ test_uris = [
20
+ {
21
+ src: 'http://youpy.jottit.com/trivia?m=diff&r=525&r=526#fuba',
22
+ expected: 'http://youpy.jottit.com/trivia'
23
+ },
24
+ {
25
+ src: 'http://youpy.jottit.com/trivia#fuba',
26
+ expected: 'http://youpy.jottit.com/trivia'
27
+ },
28
+ {
29
+ src: 'http://youpy.jottit.com/#aaa',
30
+ expected: 'http://youpy.jottit.com/'
31
+ },
32
+ {
33
+ src: 'http://youpy.jottit.com/trivia',
34
+ expected: 'http://youpy.jottit.com/trivia'
35
+ }
36
+ ]
37
+ test_uris.each do |data|
38
+ JottitTo.normalize_uri(data[:src]).must_equal data[:expected]
39
+ end
40
+ end
41
+
42
+ def html_of_fixture
43
+ #raw_html = URI('http://youpy.jottit.com/trivia').read
44
+ File.read(File.join(File.dirname(__FILE__), './fixture.html'))
45
+ end
46
+
47
+ it 'can parse a structure like a site of jottit' do
48
+ items = JottitTo.parse_html(html_of_fixture)
49
+ items.must_equal %w(foo bar buzz piyo)
50
+ end
51
+
52
+ it 'can parse with uri' do
53
+ # make stub with webmock
54
+ stub_request(:get, 'www.example.com').to_return(body: html_of_fixture)
55
+
56
+ items = JottitTo.parse_uri('http://www.example.com/')
57
+ items.must_equal %w(foo bar buzz piyo)
58
+ end
59
+ end
60
+
61
+ describe JottitTo::ArrayExtender do
62
+ it 'can convert self to xml' do
63
+ fixtures.each{|item, array|
64
+ array.to_xml.must_equal item['expected_as_xml'] }
65
+ end
66
+
67
+ it 'can convert self to text' do
68
+ fixtures.each{|item, array|
69
+ array.to_text.must_equal item['expected_as_text'] }
70
+ end
71
+
72
+ it 'can convert self to json' do
73
+ fixtures.each{|item, array|
74
+ array.to_json.must_equal item['expected_as_json'] }
75
+ end
76
+
77
+ it 'can convert self to yaml' do
78
+ fixtures.each{|item, array|
79
+ array.to_yaml.must_equal item['expected_as_yaml'] }
80
+ end
81
+
82
+ def fixtures
83
+ @yaml ||= YAML.load File.read(
84
+ File.join(File.dirname(__FILE__), './fixture-array-extender.yaml'))
85
+
86
+ @yaml.map{|item|
87
+ array = item['src'].dup
88
+ array.extend(JottitTo::ArrayExtender)
89
+ [item, array]
90
+ }
91
+ end
92
+ end
93
+
94
+ describe 'bin/' do
95
+ it 'works run(help)' do
96
+ io = IO.popen([File.join(File.dirname(__FILE__), '../bin/jottit-to'), err: [:child, :out]])
97
+ io.read.must_match(/Commands:/)
98
+ end
99
+ end
100
+
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jottit-to
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - toooooooby
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: builder
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.17'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.17'
97
+ description: A tool for converting a list in jottit page to any formats
98
+ email:
99
+ - toby.net.info.mail+git@gmail.com
100
+ executables:
101
+ - jottit-to
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/jottit-to
112
+ - jottit-to.gemspec
113
+ - lib/jottit-to.rb
114
+ - lib/jottit/version.rb
115
+ - test/fixture-array-extender.yaml
116
+ - test/fixture.html
117
+ - test/test_jottit-to.rb
118
+ homepage: https://github.com/toooooooby/jottit-to
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.0
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Jottit list page converter CLI
142
+ test_files:
143
+ - test/fixture-array-extender.yaml
144
+ - test/fixture.html
145
+ - test/test_jottit-to.rb