jtag 0.1.19 → 0.1.21

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,9 @@
1
+ complete -F get_jtag_targets jtag
2
+ function get_jtag_targets()
3
+ {
4
+ if [ -z $2 ] ; then
5
+ COMPREPLY=(`jtag help -c`)
6
+ else
7
+ COMPREPLY=(`jtag help -c $2`)
8
+ fi
9
+ }
data/jtag.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # Ensure we require the local version and not one we might have installed already
2
+ require "./lib/jtag/version.rb"
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = "jtag"
5
+ s.version = Jtag::VERSION
6
+ s.author = "Brett Terpstra"
7
+ s.email = "me@brettterpstra.com"
8
+ s.homepage = "http://brettterpstra.com"
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = "Auto-tagging and tagging tools for Jekyll"
11
+ # Add your other files here if you make them
12
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.strip =~ %r{^((test|spec|features)/|\.git|buildnotes|.*\.taskpaper)} }
13
+
14
+ s.require_paths << "lib"
15
+ s.extra_rdoc_files = ["README.rdoc", "jtag.rdoc"]
16
+ s.rdoc_options << "--title" << "jtag" << "--main" << "README.rdoc"
17
+ s.bindir = "bin"
18
+ s.executables << "jtag"
19
+ s.add_development_dependency("rake")
20
+ s.add_development_dependency("rdoc")
21
+ s.add_development_dependency("aruba")
22
+ s.add_runtime_dependency("gli", "= 2.20.0")
23
+ s.add_runtime_dependency("plist")
24
+ s.add_runtime_dependency("csv")
25
+ end
data/lib/jtag/array.rb ADDED
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+ module JekyllTag
3
+ class ::Array
4
+ #
5
+ # Stringify keys in an array of hashes or arrays
6
+ #
7
+ # @return [Array] Array with nested hash keys stringified
8
+ #
9
+ def stringify_keys
10
+ each_with_object([]) do |v, arr|
11
+ arr << if v.is_a?(Hash)
12
+ v.stringify_keys
13
+ elsif v.is_a?(Array)
14
+ v.map { |x| x.is_a?(Hash) || x.is_a?(Array) ? x.stringify_keys : x }
15
+ else
16
+ v
17
+ end
18
+ end
19
+ end
20
+
21
+ #
22
+ # Symbolize keys in an array of hashes or arrays
23
+ #
24
+ # @return [Array] Array with nested hash keys symbolized
25
+ #
26
+ def symbolize_keys
27
+ each_with_object([]) do |v, arr|
28
+ arr << if v.is_a?(Hash)
29
+ v.symbolize_keys
30
+ elsif v.is_a?(Array)
31
+ v.map { |x| x.is_a?(Hash) || x.is_a?(Array) ? x.symbolize_keys : x }
32
+ else
33
+ v
34
+ end
35
+ end
36
+ end
37
+
38
+ def to_counts
39
+ map do |tag|
40
+ if tag.is_a?(String)
41
+ tag.to_count
42
+ else
43
+ tag
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,5 +1,6 @@
1
1
  ---
2
- tags_location: localhost/data/tags.json
2
+ tags_location: ~/Desktop/Code/jtag/test/test_data/tags.json
3
3
  min_matches: 2
4
- default_post_location:
4
+ default_post_location: ~/Desktop/Code/jtag/test/test_posts/
5
5
  tags_key: tags
6
+ post_extension: md
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FileNotFound < StandardError
4
+ def initialize(msg = "File not found")
5
+ super(msg)
6
+ end
7
+ end
8
+
9
+ class NoTagsFound < StandardError
10
+ def initialize(msg = "No tags found in input")
11
+ super(msg)
12
+ end
13
+ end
14
+
15
+ class NoResults < StandardError
16
+ def initialize(msg = "No results")
17
+ super(msg)
18
+ end
19
+ end
20
+
21
+ class NoValidFile < StandardError
22
+ def initialize(msg = "No valid filename in arguments")
23
+ super(msg)
24
+ end
25
+ end
26
+
27
+ class InvalidTagsFile < StandardError
28
+ def initialize(msg = "Invalid tags file")
29
+ super(msg)
30
+ end
31
+ end
data/lib/jtag/hash.rb ADDED
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllTag
4
+ class ::Hash
5
+ ## Turn all keys into string
6
+ ##
7
+ ## @return [Hash] copy of the hash where all its keys are strings
8
+ ##
9
+ def stringify_keys
10
+ each_with_object({}) do |(k, v), hsh|
11
+ hsh[k.to_s] = if v.is_a?(Hash) || v.is_a?(Array)
12
+ v.stringify_keys
13
+ else
14
+ v
15
+ end
16
+ end
17
+ end
18
+
19
+ ##
20
+ ## Turn all keys into symbols
21
+ ##
22
+ ## @return [Hash] hash with symbolized keys
23
+ ##
24
+ def symbolize_keys
25
+ each_with_object({}) do |(k, v), hsh|
26
+ hsh[k.to_sym] = if v.is_a?(Hash) || v.is_a?(Array)
27
+ v.symbolize_keys
28
+ else
29
+ v
30
+ end
31
+ end
32
+ end
33
+
34
+ ##
35
+ ## Merge two hashes recursively (destructive)
36
+ ##
37
+ ## @see Hash#deep_merge
38
+ ##
39
+ ## @param [Hash] other hash to merge
40
+ ##
41
+ ## @return [Hash] merged hash
42
+ ##
43
+ def deep_merge!(other)
44
+ replace dup.deep_merge(other)
45
+ end
46
+
47
+ ##
48
+ ## Merge two hashes recursively
49
+ ##
50
+ ## @param [Hash] other hash to merge
51
+ ##
52
+ ## @return [Hash] merged hash
53
+ ##
54
+ ## @note This method is not the same as Hash#merge! because it merges recursively
55
+ ##
56
+ ## @example Merge two hashes
57
+ ## { a: 1, b: { c: 2 } }.deep_merge({ b: { d: 3 } })
58
+ ## # => { a: 1, b: { c: 2, d: 3 } }
59
+ ##
60
+ ## @example Merge two hashes with arrays
61
+ ## { a: [1, 2] }.deep_merge({ a: [3] })
62
+ ## # => { a: [1, 2, 3] }
63
+ ##
64
+ ## @example Merge two hashes with arrays and hashes
65
+ ## { a: [1, 2], b: { c: 3 } }.deep_merge({ a: [3], b: { d: 4 } })
66
+ ## # => { a: [1, 2, 3], b: { c: 3, d: 4 } }
67
+ ##
68
+ ## @example Merge two hashes with arrays and hashes and strings
69
+ ## { a: [1, 2], b: { c: 3 } }.deep_merge({ a: [3], b: { d: 4 }, e: "string" })
70
+ ## # => { a: [1, 2, 3], b: { c: 3, d: 4 }, e: "string" }
71
+ ##
72
+ ## @example Merge two hashes with arrays and hashes and strings and nil
73
+ ## { a: [1, 2], b: { c: 3 } }.deep_merge({ a: [3], b: { d: 4 }, e: "string", f: nil })
74
+ ## # => { a: [1, 2, 3], b: { c: 3, d: 4 }, e: "string", f: nil }
75
+ ##
76
+ ## @return [Hash]
77
+ ##
78
+ def deep_merge(other)
79
+ other.each_pair do |k, v|
80
+ tv = self[k]
81
+ self[k] = if tv.is_a?(Hash) && v.is_a?(Hash)
82
+ tv.deep_merge(v)
83
+ else
84
+ v
85
+ end
86
+ end
87
+ self
88
+ end
89
+
90
+ ##
91
+ ## Convert hash to array with parenthetical counts
92
+ ##
93
+ ## @return [Array] array of tags with parenthetical counts
94
+ ##
95
+ def to_counts
96
+ if key?("tag_counts")
97
+ self["tag_counts"]
98
+ elsif key?("tags")
99
+ self["tags"].map(&:to_count)
100
+ end
101
+ end
102
+ end
103
+ end