tidtools 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +14 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +48 -0
- data/Rakefile +26 -0
- data/bin/tidgrep +10 -0
- data/lib/tidgrep/cli.rb +90 -0
- data/lib/tidtools.rb +6 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_helper.rb +3 -0
- data/test/test_tidgrep_cli.rb +14 -0
- data/test/test_tidtools.rb +11 -0
- metadata +108 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= tidtools
|
2
|
+
|
3
|
+
* http://github.com/#{github_username}/#{project_name}
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
FIX (describe your package)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2010 ongaeshi
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/tidtools'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'tidtools' do
|
14
|
+
self.developer 'ongaeshi', 'ongaeshi@example.com'
|
15
|
+
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
|
+
self.rubyforge_name = self.name # TODO this is default value
|
17
|
+
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'newgem/tasks'
|
22
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
23
|
+
|
24
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
25
|
+
# remove_task :default
|
26
|
+
# task :default => [:spec, :features]
|
data/bin/tidgrep
ADDED
data/lib/tidgrep/cli.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../tidtools/tiddle')
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module Tidgrep
|
5
|
+
class CLI
|
6
|
+
def self.isValidOption(file_name, title, keyword)
|
7
|
+
return false if !file_name
|
8
|
+
return title || keyword
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.execute(stdout, arguments=[])
|
12
|
+
title = nil
|
13
|
+
regexp_option = 0
|
14
|
+
file_name = ENV['TIDGREP_PATH']
|
15
|
+
report = false
|
16
|
+
match_rule = "grep"
|
17
|
+
|
18
|
+
opt = OptionParser.new('tidgrep [option] keyword')
|
19
|
+
opt.on('-f FILE_NAME', '--filename FILE_NAME', 'TiddlyWiki file name') {|v| file_name = v }
|
20
|
+
opt.on('-t TITLE', '--title TITLE', 'match title') {|v| title = v }
|
21
|
+
opt.on('-i', '--ignore', 'ignore case') {|v| regexp_option |= Regexp::IGNORECASE }
|
22
|
+
opt.on('-r', '--report', 'disp report') {|v| report = true }
|
23
|
+
opt.on('-m MATCH_RULE', '--match MATCH_RULE', 'match rule [grep, tiddle, hr]') {|v| match_rule = v; p match_rule }
|
24
|
+
opt.parse!(arguments)
|
25
|
+
|
26
|
+
keyword = ARGV[0]
|
27
|
+
|
28
|
+
if (!isValidOption(file_name, title, keyword))
|
29
|
+
puts opt.help
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
|
33
|
+
tiddles = Tiddle.parse_sort_modified(file_name)
|
34
|
+
match_lines = 0
|
35
|
+
total_lines = 0
|
36
|
+
match_tiddles = 0
|
37
|
+
|
38
|
+
title_regexp = title && Regexp.new(title, regexp_option)
|
39
|
+
content_regexp = keyword && Regexp.new(keyword, regexp_option)
|
40
|
+
|
41
|
+
tiddles.each do |tiddle|
|
42
|
+
next if (title && tiddle.title !~ title_regexp)
|
43
|
+
is_match_tiddle = false
|
44
|
+
line_no = 1
|
45
|
+
|
46
|
+
if (content_regexp)
|
47
|
+
tiddle.content.each_line do |line|
|
48
|
+
if (content_regexp =~ line)
|
49
|
+
case match_rule
|
50
|
+
when "grep"
|
51
|
+
puts "#{tiddle.title}:#{line_no}:#{line}"
|
52
|
+
match_lines += 1
|
53
|
+
unless is_match_tiddle
|
54
|
+
match_tiddles += 1
|
55
|
+
is_match_tiddle = true
|
56
|
+
end
|
57
|
+
when "tiddle"
|
58
|
+
match_lines += 1
|
59
|
+
unless is_match_tiddle
|
60
|
+
puts "--- #{tiddle.title} --------------------"
|
61
|
+
match_tiddles += 1
|
62
|
+
is_match_tiddle = true
|
63
|
+
end
|
64
|
+
puts "#{line}"
|
65
|
+
when "hr"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
line_no += 1
|
69
|
+
total_lines += 1
|
70
|
+
end
|
71
|
+
else
|
72
|
+
puts tiddle.title
|
73
|
+
match_tiddles += 1
|
74
|
+
is_match_tiddle = true
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
if (report)
|
80
|
+
puts "------------------------------"
|
81
|
+
if (content_regexp)
|
82
|
+
puts "match lines : #{match_lines}"
|
83
|
+
puts "total lines : #{total_lines}"
|
84
|
+
end
|
85
|
+
puts "match tiddles : #{match_tiddles}"
|
86
|
+
puts "total tiddles : #{tiddles.size}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/tidtools.rb
ADDED
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/tidtools.rb'}"
|
9
|
+
puts "Loading tidtools gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper.rb")
|
2
|
+
require 'tidgrep/cli'
|
3
|
+
|
4
|
+
class TestTidgrepCli < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Tidgrep::CLI.execute(@stdout_io = StringIO.new, [])
|
7
|
+
@stdout_io.rewind
|
8
|
+
@stdout = @stdout_io.read
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_print_default_output
|
12
|
+
assert_match(/To update this executable/, @stdout)
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tidtools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- ongaeshi
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-24 00:00:00 +09:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rubyforge
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 0
|
30
|
+
- 4
|
31
|
+
version: 2.0.4
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: hoe
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 6
|
44
|
+
- 0
|
45
|
+
version: 2.6.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description: FIX (describe your package)
|
49
|
+
email:
|
50
|
+
- ongaeshi@example.com
|
51
|
+
executables:
|
52
|
+
- tidgrep
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- History.txt
|
57
|
+
- Manifest.txt
|
58
|
+
- PostInstall.txt
|
59
|
+
files:
|
60
|
+
- History.txt
|
61
|
+
- Manifest.txt
|
62
|
+
- PostInstall.txt
|
63
|
+
- README.rdoc
|
64
|
+
- Rakefile
|
65
|
+
- bin/tidgrep
|
66
|
+
- lib/tidgrep/cli.rb
|
67
|
+
- lib/tidtools.rb
|
68
|
+
- script/console
|
69
|
+
- script/destroy
|
70
|
+
- script/generate
|
71
|
+
- test/test_helper.rb
|
72
|
+
- test/test_tidgrep_cli.rb
|
73
|
+
- test/test_tidtools.rb
|
74
|
+
has_rdoc: true
|
75
|
+
homepage: http://github.com/#{github_username}/#{project_name}
|
76
|
+
licenses: []
|
77
|
+
|
78
|
+
post_install_message: PostInstall.txt
|
79
|
+
rdoc_options:
|
80
|
+
- --main
|
81
|
+
- README.rdoc
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project: tidtools
|
101
|
+
rubygems_version: 1.3.6
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: FIX (describe your package)
|
105
|
+
test_files:
|
106
|
+
- test/test_helper.rb
|
107
|
+
- test/test_tidgrep_cli.rb
|
108
|
+
- test/test_tidtools.rb
|