gnote 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ /rfrom/
2
+ /*.gem
3
+ /Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ #source "https://rubygems.org"
2
+ source "http://ruby.taobao.org"
3
+
4
+ gem "pd"
5
+ gem "tagen", :path => "/home/guten/dev/one/tagen"
6
+ gem "optimism"
7
+ gem "pa", :path => "/home/guten/dev/one/pa"
8
+ gem "thor"
9
+ gem "rb-inotify"
10
+
11
+ group :development do
12
+ gem "rspec"
13
+ gem "watchr"
14
+ gem "rag"
15
+ end
16
+
17
+ #gemspec
@@ -0,0 +1,58 @@
1
+ gnote, hello world
2
+ ========================
3
+
4
+ | Homepage: | https://github.com/GutenYe/gnote |
5
+ |----------------|------------------------------------------------------ |
6
+ | Author: | Guten |
7
+ | License: | MIT-LICENSE |
8
+ | Documentation: | http://rubydoc.info/gems/gnote/frames |
9
+ | Issue Tracker: | https://github.com/GutenYe/gnote/issues |
10
+
11
+ descripe your prjoect here.
12
+
13
+ Getting started
14
+ ---------------
15
+
16
+ $ gnote watch -V
17
+
18
+
19
+ Install
20
+ -------
21
+
22
+ gem install gnote
23
+
24
+ mkdir ~/note
25
+ mkdir ~/.note.tags
26
+
27
+ Note on Patches/Pull Requests
28
+ -----------------------------
29
+
30
+ 1. Fork the project.
31
+ 2. Make your feature addition or bug fix.
32
+ 3. Add tests for it. This is important so I don't break it in a future version unintentionally.
33
+ 4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
34
+ 5. Send me a pull request. Bonus points for topic branches.
35
+ 6. Coding Style Guide: https://gist.github.com/1105334
36
+
37
+ Credits
38
+ -------
39
+
40
+ * [Contributors](https://github.com/GutenYe/gnote/contributors)
41
+
42
+ Resources
43
+ ---------
44
+
45
+ some related resources to help each other.
46
+
47
+ Copyright
48
+ ---------
49
+
50
+ (the MIT License)
51
+
52
+ Copyright (c) 2012 Guten
53
+
54
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
55
+
56
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
57
+
58
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Ragfile ADDED
@@ -0,0 +1,5 @@
1
+ # add your own task in Ragfile or in tasks/*.rag
2
+ class Rag < Thor
3
+ end
4
+
5
+ # vim: ft=ruby
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
4
+ require "bundler/setup"
5
+
6
+ load File.expand_path("../gnote", __FILE__)
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/gnote"
4
+
5
+ begin
6
+ GNote::CLI.start
7
+ rescue GNote::Error => e
8
+ GNote.ui.error e.message
9
+ GNote.ui.debug e.backtrace.join("\n")
10
+ exit 1
11
+ rescue Interrupt => e
12
+ GNote.ui.error "\nQuitting..."
13
+ GNote.ui.debug e.backtrace.join("\n")
14
+ exit 1
15
+ rescue Exception => e
16
+ raise e
17
+ exit 1
18
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require "fileutils"
3
+ require "mkmf"
4
+
5
+ # FileUtils.install File.expand_path("../bin/gnote", __FILE__), Gem.bindir
6
+
7
+ create_makefile("gnote")
@@ -0,0 +1,24 @@
1
+ Kernel.load File.expand_path("../lib/gnote/version.rb", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "gnote"
5
+ s.version = GNote::VERSION
6
+ s.summary = "a gnote.vim plugin"
7
+ s.description = <<-EOF
8
+ a gnote.vim plugin
9
+ EOF
10
+
11
+ s.author = "Guten"
12
+ s.email = "ywzhaifei@gmail.com"
13
+ s.homepage = "http://github.com/GutenYe/gnote-plugin"
14
+ s.rubyforge_project = "xx"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.executables = ["gnote"]
18
+ #s.extensions << "extconf.rb"
19
+
20
+ s.add_dependency "tagen"
21
+ s.add_dependency "optimism"
22
+ s.add_dependency "pa"
23
+ s.add_dependency "thor"
24
+ end
@@ -0,0 +1,23 @@
1
+ # lib/**/*.rb
2
+ watch %r~lib/(.*)\.rb~ do |m|
3
+ test "spec/#{m[1]}_spec.rb"
4
+ end
5
+
6
+ # spec/**/*_spec.rb
7
+ watch %r~spec/.*_spec\.rb~ do |m|
8
+ test m[0]
9
+ end
10
+
11
+ # Ctrl-\
12
+ Signal.trap('QUIT') do
13
+ puts "--- Running all tests ---\n\n"
14
+ test "spec"
15
+ end
16
+
17
+ def test(path)
18
+ system "clear"
19
+ cmd = "rspec #{path}"
20
+ puts cmd
21
+ system cmd
22
+ end
23
+
@@ -0,0 +1,27 @@
1
+ libdir = File.dirname(__FILE__); $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
2
+
3
+ require "pd"
4
+ require "tagen/core"
5
+ require "optimism"
6
+ require "pa"
7
+
8
+ module GNote
9
+ DEBUG = true
10
+
11
+ autoload :VERSION, "gnote/version"
12
+ autoload :UI, "gnote/ui"
13
+ autoload :CLI, "gnote/cli"
14
+ autoload :Tags, "gnote/tags"
15
+
16
+ Error = Class.new Exception
17
+ EFatal = Class.new Exception
18
+ Rc = Optimism.require "gnote/rc", "~/.gnoterc"
19
+
20
+ class << self
21
+ attr_accessor :ui
22
+
23
+ def ui
24
+ @ui ||= UI.new
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ require "thor"
2
+
3
+ module GNote
4
+ class CLI < Thor
5
+ class_option "no-color", :banner => "Disable colorization in output", :type => :boolean
6
+ class_option "verbose", :aliases => "-V", :banner => "Enable verbose output mode", :type => :boolean
7
+
8
+ attr_reader :o
9
+
10
+ def initialize(*)
11
+ super
12
+ o = @o = options.dup
13
+ the_shell = (options["no-color"] ? Thor::Shell::Basic.new : shell)
14
+ GNote.ui = UI::Shell.new(the_shell)
15
+ GNote.ui.debug! if options["verbose"]
16
+ end
17
+
18
+ desc "tags", "generate a tags file"
19
+ def tags
20
+ GNote::Tags.tags
21
+ end
22
+
23
+ desc "watch", "watch note/ directory, and automatical generate tags file"
24
+ def watch
25
+ GNote::Tags.watch
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,8 @@
1
+ p:
2
+ root = Pa.dir(__FILE__).parent(2)
3
+ project = Pa("~/gnote")
4
+ home = Pa("~/.gnote")
5
+ homerc = Pa("~/.gnoterc")
6
+
7
+ note = Pa("~/note")
8
+ tagsdir = Pa("~/.note.tags")
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+ require "rb-inotify"
3
+
4
+ module GNote
5
+ class Tags
6
+ class << self
7
+ def watch
8
+ Tags.new.watch
9
+ end
10
+
11
+ def tags
12
+ Tags.new.tags
13
+ end
14
+ end
15
+
16
+ # @example
17
+ #
18
+ # generate_tags(Pa("hello.gnote"))
19
+ def generate_tags(file)
20
+ content = ""
21
+
22
+ File.read("#{Rc.p.note}/#{file}").scan(/∗([^\n ]+)∗/) {|(id)|
23
+ content << "#{id}\t#{file}\t/∗#{id}∗\n"
24
+ }
25
+
26
+ File.write "#{Rc.p.tagsdir}/#{file}", content, :mkdir => true
27
+ end
28
+
29
+ def concat_tags
30
+ content = ""
31
+ Pa.each_r(Rc.p.tagsdir) {|p|
32
+ content << File.read(p.p)
33
+ }
34
+
35
+ content = sort(content)
36
+
37
+ content = <<-EOF
38
+ !_TAG_FILE_SORTED\t1
39
+
40
+ #{content}
41
+ EOF
42
+
43
+ File.write "#{Rc.p.note}/tags", content
44
+ end
45
+
46
+ def sort(content)
47
+ content = content.split(/\n/)
48
+ content = content.sort_by{|v| v.split(/\t/)[0]}
49
+ content.join("\n") + "\n"
50
+ end
51
+
52
+ # task
53
+ def tags
54
+ Pa.empty_dir Rc.p.tagsdir
55
+
56
+ Pa.each_r(Rc.p.note) {|p|
57
+ next if skip_file(p.rel)
58
+
59
+ generate_tags(p.rel)
60
+ }
61
+
62
+ concat_tags
63
+ end
64
+
65
+ # task
66
+ def watch
67
+ notifier = INotify::Notifier.new
68
+
69
+ notifier.watch(Rc.p.note.p, :modify, :delete, :recursive) { |e|
70
+ file = Pa(e.name) # "ds/pa.gnote"
71
+ if skip_file(file)
72
+ # skip
73
+ else
74
+ if e.flags.include?(:modify)
75
+ GNote.ui.debug "MODIFY #{file}"
76
+ generate_tags(file)
77
+ elsif e.flags.include?(:delete)
78
+ GNote.ui.debug "DELETE #{file}"
79
+ Pa.rm "#{Rc.p.tagsdir}/#{file}"
80
+ end
81
+
82
+ concat_tags
83
+ end
84
+ }
85
+
86
+ GNote.ui.say ">> BEGIN WATCH AT #{Rc.p.note}"
87
+ notifier.run
88
+ end
89
+
90
+ private
91
+ # skip_file(Pa("foo/bar.gnote"))
92
+ #
93
+ # tags
94
+ # vim: .swp backup~
95
+ def skip_file(file)
96
+ file = file.p
97
+
98
+ %w[tags].include?(file) ||
99
+ file =~ /^\..*\.swp$/ ||
100
+ file =~ /~$/
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,61 @@
1
+ module GNote
2
+ class UI
3
+ def warn(message)
4
+ end
5
+
6
+ def debug(message)
7
+ end
8
+
9
+ def error(message)
10
+ end
11
+
12
+ def info(message)
13
+ end
14
+
15
+ def confirm(message)
16
+ end
17
+
18
+ # alias to info.
19
+ def say(*args, &blk)
20
+ info(*args, &blk)
21
+ end
22
+
23
+ class Shell < UI
24
+ attr_writer :shell
25
+
26
+ def initialize(shell)
27
+ @shell = shell
28
+ @quiet = false
29
+ @debug = ENV['DEBUG']
30
+ end
31
+
32
+ def debug(msg)
33
+ @shell.say(msg) if @debug && !@quiet
34
+ end
35
+
36
+ def info(msg)
37
+ @shell.say(msg) if !@quiet
38
+ end
39
+
40
+ def confirm(msg)
41
+ @shell.say(msg, :green) if !@quiet
42
+ end
43
+
44
+ def warn(msg)
45
+ @shell.say(msg, :yellow)
46
+ end
47
+
48
+ def error(msg)
49
+ @shell.say(msg, :red)
50
+ end
51
+
52
+ def be_quiet!
53
+ @quiet = true
54
+ end
55
+
56
+ def debug!
57
+ @debug = true
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,3 @@
1
+ module GNote
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,2 @@
1
+
2
+ ∥from∥ ∗to∗
@@ -0,0 +1,87 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+
4
+ Tags = GNote::Tags
5
+
6
+ class Tags
7
+ public :skip_file
8
+ end
9
+
10
+
11
+ describe Tags do
12
+ before :each do
13
+ Pa.empty_dir Rc.p.note
14
+ Pa.empty_dir Rc.p.tagsdir
15
+
16
+ @tags = Tags.new
17
+ end
18
+
19
+ describe "#generate_tags" do
20
+ # note/
21
+ # dir/hello with "∗id∗\n"
22
+ before :each do
23
+ File.write "#{Rc.p.note}/dir/hello", "∗id∗\n", :mkdir => true
24
+ end
25
+
26
+ it "works" do
27
+ @tags.generate_tags(Pa("dir/hello"))
28
+
29
+ File.read("#{Rc.p.tagsdir}/dir/hello").should =~ %r~id\tdir/hello\t\/∗id∗\n~
30
+ end
31
+ end
32
+
33
+ describe "#concat_tags" do
34
+ # .note.tags/
35
+ # foo with "foo\n"
36
+ # bar with "bar\n"
37
+ before :each do
38
+ File.write "#{Rc.p.tagsdir}/foo", "foo\n"
39
+ File.write "#{Rc.p.tagsdir}/bar", "bar\n"
40
+ end
41
+
42
+ it "works" do
43
+ @tags.concat_tags
44
+
45
+ File.read("#{Rc.p.note}/tags").should =~ %r~bar\nfoo~
46
+ end
47
+ end
48
+
49
+ describe "#sort" do
50
+ it "works" do
51
+ a = "foo\nbar\n"
52
+ b = "bar\nfoo\n"
53
+
54
+ @tags.sort(a).should == b
55
+ end
56
+ end
57
+
58
+ describe "#tags" do
59
+ # note/
60
+ # tags with "a"
61
+ # foo with "∗id∗"
62
+ #
63
+ # .note.tags/
64
+ # foo with "c"
65
+ before :each do
66
+ File.write "#{Rc.p.note}/tags", "a"
67
+ File.write "#{Rc.p.note}/foo", "∗id∗"
68
+ File.write "#{Rc.p.tagsdir}/foo", "c"
69
+ end
70
+
71
+ it "works" do
72
+ @tags.tags
73
+
74
+ File.read("#{Rc.p.note}/tags").should =~ %r~id\tfoo\t\/∗id∗\n~
75
+ end
76
+ end
77
+
78
+ describe "#skip_file" do
79
+ it "works" do
80
+ @tags.skip_file(Pa("tags")).should be_true
81
+ @tags.skip_file(Pa("foo~")).should be_true
82
+ @tags.skip_file(Pa(".foo.swp")).should be_true
83
+ @tags.skip_file(Pa("foo")).should be_false
84
+ end
85
+ end
86
+ end
87
+
@@ -0,0 +1,52 @@
1
+ require "bundler/setup"
2
+ require "stringio"
3
+ require "gnote"
4
+
5
+ $spec_dir = File.expand_path("..", __FILE__)
6
+ $spec_data = File.expand_path("../data", __FILE__)
7
+
8
+ Rc = GNote::Rc
9
+ Rc._merge! Optimism <<EOF
10
+ p:
11
+ note = Pa("#{$spec_data}/note")
12
+ tagsdir = Pa("#{$spec_data}/_note.tags")
13
+ EOF
14
+
15
+ RSpec.configure do |config|
16
+ def capture(stream)
17
+ begin
18
+ stream = stream.to_s
19
+ eval "$#{stream} = StringIO.new"
20
+ yield
21
+ result = eval("$#{stream}").string
22
+ ensure
23
+ eval("$#{stream} = #{stream.upcase}")
24
+ end
25
+
26
+ result
27
+ end
28
+
29
+ alias :silence :capture
30
+ end
31
+
32
+ module Kernel
33
+ private
34
+
35
+ def xdescribe(*args, &blk)
36
+ describe *args do
37
+ pending "xxxxxxxxx"
38
+ end
39
+ end
40
+
41
+ def xcontext(*args, &blk)
42
+ context *args do
43
+ pending "xxxxxxxxx"
44
+ end
45
+ end
46
+
47
+ def xit(*args, &blk)
48
+ it *args do
49
+ pending "xxxxxxxx"
50
+ end
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gnote
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Guten
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: tagen
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: optimism
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pa
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: thor
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ! 'a gnote.vim plugin
79
+
80
+ '
81
+ email: ywzhaifei@gmail.com
82
+ executables:
83
+ - gnote
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - .gitignore
88
+ - .rspec
89
+ - Gemfile
90
+ - README.md
91
+ - Ragfile
92
+ - bin/1gnote
93
+ - bin/gnote
94
+ - extconf.rb
95
+ - gnote.gemspec
96
+ - gnote.watchr
97
+ - lib/gnote.rb
98
+ - lib/gnote/cli.rb
99
+ - lib/gnote/rc.rb
100
+ - lib/gnote/tags.rb
101
+ - lib/gnote/ui.rb
102
+ - lib/gnote/version.rb
103
+ - note/a.gnote
104
+ - spec/gnote/tags_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: http://github.com/GutenYe/gnote-plugin
107
+ licenses: []
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ segments:
119
+ - 0
120
+ hash: -1874467495478973641
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project: xx
129
+ rubygems_version: 1.8.21
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: a gnote.vim plugin
133
+ test_files: []
134
+ has_rdoc: