tagline 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 86d24152825e6c3f83da329e3555758ce0e5ba5a
4
+ data.tar.gz: 25a39fd47efc9ad678c0b233ffbc897db55c4e1e
5
+ SHA512:
6
+ metadata.gz: 5dafdcf5d4696b0c2a0147f52379f77934069f43a247f3a510edea0232d0a9429af943431a945c1a6311cec9e8f5bf3b9ca663fad0fa3f1672b47da792730176
7
+ data.tar.gz: 931c1eb845f66b070c34a3bc036e061c20bb6180a0e09dc6d64e050d5c1e3fa3c5dbe39562fad2cfe0a8afbcad4d4bd6a731c9571b13eb2ee48cc0d9091fa49f
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Max White
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,43 @@
1
+ # Tagline
2
+
3
+ Simple command line tool for tagging lines of text. Intended for reviewing a long list, separted by new lines. Creates new files for each tag of only the items tagged, so that it can be used to organise lists into sub lists.
4
+
5
+ ## Installation
6
+
7
+ $ gem install tagline
8
+
9
+ ## Usage
10
+
11
+ $ tagline -f my_list.txt -t tag1:116 -t tag2:100 -t tag3:122
12
+
13
+ ```
14
+ ********** Tagline *************
15
+ ********************************
16
+
17
+ * Press UP to see previous
18
+ * Press DOWN to see next
19
+ * Press "t" to toggle tag1
20
+ * Press "d" to toggle tag2
21
+ * Press "z" to toggle tag3
22
+ * Press "n" to toggle next_on_tag
23
+ * Press CTRL+X to exit
24
+
25
+ Tags:
26
+ tag1: false
27
+ tag2: false
28
+ tag3: false
29
+
30
+ => My first line of text!
31
+ ```
32
+
33
+ The tag argument expects a tagname:ascii-code pair. ascii codes can be looked-up [here](docs/ascii_codes.md).
34
+
35
+ The default tags are ENTER for pass and 'f' for flag.
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it ( https://github.com/[my-github-username]/tagline/fork )
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create a new Pull Request
data/bin/tagline ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'slop'
4
+ require 'tagline'
5
+
6
+ opts = Slop.parse do |o|
7
+ o.string '-f', '--filename', 'file to be reviewed'
8
+ o.array '-t', '--tags', 'tag name:ascii code'
9
+ o.on '-h', '--help', 'print this' do
10
+ puts(o) && exit
11
+ end
12
+ end
13
+
14
+ unless opts[:filename]
15
+ puts opts
16
+ exit
17
+ end
18
+
19
+ filename = File.expand_path(opts[:filename], Dir.getwd)
20
+ fail 'File does not exist' unless File.exist?(filename)
21
+
22
+ unless opts[:tags].empty?
23
+ Tagline.tags = opts[:tags].reduce({}) do |h, arg|
24
+ tag, code = arg.split(':')
25
+ fail 'Tags must be in name:ascii code pairs, e.g. pass:13' unless code
26
+ h.merge(tag.to_sym => code.to_i)
27
+ end
28
+ end
29
+
30
+ Tagline.review(filename)
data/lib/tagline.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'forwardable'
2
+ require 'tagline/tagger'
3
+
4
+ module Tagline
5
+ class << self
6
+ attr_accessor :next_on_tag, :tags
7
+
8
+ def review(filename)
9
+ Tagger.run_loop(filename)
10
+ end
11
+ end
12
+
13
+ self.next_on_tag = false
14
+ self.tags = { pass: 13, flag: 102 }
15
+ end
@@ -0,0 +1,37 @@
1
+ require 'highline/system_extensions'
2
+
3
+ module Tagline
4
+ class CharacterReader
5
+ include HighLine::SystemExtensions
6
+
7
+ def self.run_loop(*args)
8
+ new(*args).run_loop
9
+ end
10
+
11
+ UP = 72
12
+ DOWN = 80
13
+ N = 110
14
+ CTRL_X = 24
15
+
16
+ def run_loop
17
+ before_loop
18
+ loop do
19
+ case char = get_character.ord
20
+ when UP
21
+ up_key
22
+ when DOWN
23
+ down_key
24
+ when N
25
+ n_key
26
+ when CTRL_X
27
+ break
28
+ else
29
+ tag(char)
30
+ end
31
+ end
32
+ ensure
33
+ after_loop
34
+ exit
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,20 @@
1
+ module Tagline
2
+ class Line
3
+ extend Forwardable
4
+ attr_reader :text
5
+ def_delegators :tags, :[], :[]=
6
+
7
+ def initialize(text)
8
+ @text = text
9
+ @tags = Hash.new(false)
10
+ end
11
+
12
+ def toggle(tag)
13
+ self[tag] = !self[tag]
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :tags
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ require 'tagline/line'
2
+
3
+ module Tagline
4
+ class LineManager
5
+ extend Forwardable
6
+ attr_reader :lines
7
+
8
+ def initialize(filename)
9
+ @lines = File.read(filename).split("\n").map do |line|
10
+ Line.new(line)
11
+ end
12
+ end
13
+
14
+ def line
15
+ lines[i]
16
+ end
17
+
18
+ def next_line
19
+ @i = (i + 1) % length
20
+ end
21
+
22
+ def previous_line
23
+ @i = (i - 1) % length
24
+ end
25
+
26
+ private
27
+
28
+ def_delegator :lines, :length
29
+
30
+ def i
31
+ @i ||= 0
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ module Tagline
2
+ module ScreenPrinter
3
+ class << self
4
+ def print_screen(line)
5
+ system('clear') || system('cls')
6
+
7
+ puts '********** Tagline *************'
8
+ puts "********************************\n\n"
9
+ puts ' * Press UP to see previous'
10
+ puts ' * Press DOWN to see next'
11
+ Tagline.tags.each do |tag, chord|
12
+ puts " * Press #{chord.chr.inspect} to toggle #{tag}"
13
+ end
14
+ puts ' * Press "n" to toggle next_on_tag'
15
+ puts ' * Press CTRL+X to exit'
16
+
17
+ puts "\nTags: "
18
+ Tagline.tags.keys.each do |tag|
19
+ puts " #{tag}: #{line[tag]}"
20
+ end
21
+
22
+ print "\n=> #{line.text}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ module Tagline
2
+ class TagStorer
3
+ def initialize(filename, lines)
4
+ @filename, @lines = filename, lines
5
+ end
6
+
7
+ def retrieve_stored_tags
8
+ tag_names.each do |tag|
9
+ next unless File.exist?(tag_filename(tag))
10
+ tagged_lines = File.read(tag_filename(tag)).split("\n")
11
+ lines.each { |line| line[tag] = tagged_lines.include?(line.text) }
12
+ end
13
+ end
14
+
15
+ def save_tags
16
+ tag_names.each do |tag|
17
+ tagged_lines = lines.select { |line| line[tag] }.map(&:text)
18
+ next if tagged_lines.empty?
19
+ File.write(tag_filename(tag), tagged_lines.join("\n"))
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :filename, :lines
26
+
27
+ def tag_names
28
+ @tag_names ||= Tagline.tags.keys
29
+ end
30
+
31
+ def file_ext
32
+ @file_ext ||= File.extname(filename)
33
+ end
34
+
35
+ def file_without_ext
36
+ @file_without_ext ||= filename.chomp(file_ext)
37
+ end
38
+
39
+ def tag_filename(tag)
40
+ "#{file_without_ext}_#{tag}#{file_ext}"
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,39 @@
1
+ require 'tagline/character_reader'
2
+ require 'tagline/line_manager'
3
+ require 'tagline/screen_printer'
4
+ require 'tagline/tag_storer'
5
+
6
+ module Tagline
7
+ class Tagger < CharacterReader
8
+ extend Forwardable
9
+
10
+ def initialize(filename)
11
+ @filename = filename
12
+ @line_manager = LineManager.new(filename)
13
+ @tag_storer = TagStorer.new(filename, lines)
14
+ retrieve_stored_tags
15
+ end
16
+
17
+ define_method(:before_loop) { print_screen }
18
+ define_method(:up_key) { previous_line; print_screen }
19
+ define_method(:down_key) { next_line; print_screen }
20
+ define_method(:n_key) { Tagline.next_on_tag = !Tagline.next_on_tag }
21
+ define_method(:after_loop) { save_tags }
22
+
23
+ def tag(chord)
24
+ tag = Tagline.tags.invert[chord]
25
+ return unless tag
26
+ toggle(tag)
27
+ next_line if Tagline.next_on_tag
28
+ print_screen
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :filename, :line_manager, :tag_storer
34
+ def_delegators :line_manager, :lines, :line, :next_line, :previous_line
35
+ def_delegator :line, :toggle
36
+ def_delegators :tag_storer, :retrieve_stored_tags, :save_tags
37
+ define_method(:print_screen) { ScreenPrinter.print_screen(line) }
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tagline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Max White
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: highline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.21
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.21
33
+ - !ruby/object:Gem::Dependency
34
+ name: slop
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '4.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 4.0.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '4.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 4.0.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.1'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.1.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.1'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.1.0
73
+ description:
74
+ email: mushishi78@gmail.com
75
+ executables:
76
+ - tagline
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - LICENSE.txt
81
+ - README.md
82
+ - bin/tagline
83
+ - lib/tagline.rb
84
+ - lib/tagline/character_reader.rb
85
+ - lib/tagline/line.rb
86
+ - lib/tagline/line_manager.rb
87
+ - lib/tagline/screen_printer.rb
88
+ - lib/tagline/tag_storer.rb
89
+ - lib/tagline/tagger.rb
90
+ homepage:
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Simple command line tool for tagging lines of text
114
+ test_files: []