thor-cheese 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ README.rdoc
2
+ lib/thor-cheese.rb
3
+ lib/thor-cheese/ui.rb
4
+
5
+ features/**/*.feature
6
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Christocracy
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,90 @@
1
+ = Cheese
2
+
3
+ A simple {Thor-based}[http://github.com/wycats/thor] Mixin and console-application skeleton. The structure was inspired by Bundler[http://github.com/carlhuda/bundler]. Cheese provides a colourful UI Shell.
4
+
5
+ = Usage
6
+
7
+ It's very simple to create a Cheese-based console application. First create an executable in your Gem's <tt>/bin</tt> directory:
8
+
9
+ #!/usr/local/bin/ruby
10
+
11
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
12
+
13
+ require 'cheese'
14
+ require 'your-app'
15
+ require 'your-app/cli'
16
+
17
+ begin
18
+ YourApp::CLI.start
19
+ rescue YourApp::Error => e
20
+ YourApp.ui.error e.message
21
+ exit e.status_code
22
+ end
23
+
24
+ Next, in your Gem's base Module, eg: <tt>lib/your-app.rb</tt>, include the <tt>Cheese</tt> mixin and implement your <tt>Cheese::Error</tt> extensions.
25
+
26
+ module YourApp
27
+ VERSION = "0.1.0"
28
+
29
+ ##
30
+ # include the Cheese module into your base nameespace. This allows you to boot an
31
+ # instance of the colourful Cheese::UI::Sheel
32
+ #
33
+ include Cheese
34
+
35
+ # Do your autoloads here.
36
+ autoload :MightyGenerator, 'your-app/mighty-generator'
37
+
38
+ ##
39
+ # Example error-extension
40
+ #
41
+ class Error < Cheese::Error; status_code(666) ; end
42
+
43
+ end
44
+
45
+ Finally, place your Thor[http://github.com/wycats/thor] extension in your Gem's base-package, eg: <tt>lib/your-app/cli.rb</tt>. Override the constructor
46
+ and send the shell into the class-method <tt>shell</tt> mixed-in with <tt>include Cheese</tt> in the previous step.
47
+
48
+ ##
49
+ # Example Thor instance
50
+ #
51
+ module YourApp
52
+ class CLI < Thor
53
+
54
+ desc "say", "Say cheese and receive"
55
+ def say(word)
56
+ if word == 'cheese'
57
+ YourApp.ui.confirm("CHEESE!")
58
+ else
59
+ YourApp.ui.warn(" '#{word}'?? No cheese for you :(")
60
+ end
61
+ end
62
+
63
+ ##
64
+ # For your convenience, override initialize and boot an instance of XCLI::UI::Shell by sending your
65
+ # shell method mixed-in by Cheese.
66
+ # YourApp.ui.confirm("That was good cheese")
67
+ # YourApp.ui.warn("That's stinky cheese")
68
+ # YourApp.ui.error("That was horrible cheese")
69
+ #
70
+ def initialize(*)
71
+ YourApp.shell = shell
72
+ super
73
+ end
74
+ end
75
+ end
76
+
77
+
78
+ == Note on Patches/Pull Requests
79
+
80
+ * Fork the project.
81
+ * Make your feature addition or bug fix.
82
+ * Add tests for it. This is important so I don't break it in a
83
+ future version unintentionally.
84
+ * Commit, do not mess with rakefile, version, or history.
85
+ (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)
86
+ * Send me a pull request. Bonus points for topic branches.
87
+
88
+ == Copyright
89
+
90
+ Copyright (c) 2010 Christocracy. See LICENSE for details.
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "thor-cheese"
8
+ gem.summary = %Q{General Thor extension for building console-based ruby apps. Has built-in colour UI}
9
+ gem.description = %Q{General Thor extension for building console-based ruby apps with built-in colour UI}
10
+ gem.email = "christocracy@gmail.com"
11
+ gem.homepage = "http://github.com/christocracy/thor-cheese"
12
+ gem.authors = ["Christocracy"]
13
+ gem.add_dependency "thor", ">=0.13.0"
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/test_*.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+ task :test => :check_dependencies
44
+
45
+ task :default => :test
46
+
47
+ #require 'rake/rdoctask'
48
+ #Rake::RDocTask.new do |rdoc|
49
+ # version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ # rdoc.rdoc_dir = 'rdoc'
52
+ # rdoc.title = "xcli #{version}"
53
+ # rdoc.rdoc_files.include('README*')
54
+ # rdoc.rdoc_files.include('lib/thor-cheese.rb', 'lib/thor-cheese/ui.rb')
55
+ #end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,14 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'thor-cheese'
6
+ require 'your-app'
7
+ require 'your-app/cli'
8
+
9
+ begin
10
+ YourApp::CLI.start
11
+ rescue YourApp::Error => e
12
+ YourApp.ui.error e.message
13
+ exit e.status_code
14
+ end
@@ -0,0 +1,44 @@
1
+ require 'thor'
2
+ class Thor
3
+ module Cheese
4
+ VERSION = "0.1.0"
5
+
6
+ autoload :UI, 'thor-cheese/ui'
7
+
8
+ ##
9
+ # Generic class to build your own error-extensions from. Copied from Bundler
10
+ #
11
+ class Error < StandardError
12
+ def self.status_code(code = nil)
13
+ return @code unless code
14
+ @code = code
15
+ end
16
+
17
+ def status_code
18
+ self.class.status_code
19
+ end
20
+ end
21
+
22
+ ##
23
+ # Example error-extension
24
+ #
25
+ class ArgumentError < Error; status_code(666) ; end
26
+
27
+ class << self
28
+ def included(klass)
29
+ klass.send(:extend, ClassMethods)
30
+ end
31
+ end
32
+
33
+ module ClassMethods
34
+
35
+ def shell=(shell)
36
+ @ui ||= UI::Shell.new(shell)
37
+ end
38
+
39
+ def ui
40
+ @ui ||= UI.new
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,57 @@
1
+ class Thor
2
+ module Cheese
3
+ class UI
4
+ def warn(message)
5
+ end
6
+
7
+ def error(message)
8
+ end
9
+
10
+ def info(message)
11
+ end
12
+
13
+ def confirm(message)
14
+ end
15
+
16
+ class Shell < UI
17
+ def initialize(shell)
18
+ @shell = shell
19
+ end
20
+
21
+ # TODO: Add debug mode
22
+ def debug(msg)
23
+ end
24
+
25
+ def info(msg)
26
+ @shell.say(msg)
27
+ end
28
+
29
+ def confirm(msg)
30
+ @shell.say(msg, :green)
31
+ end
32
+
33
+ def warn(msg)
34
+ @shell.say(msg, :yellow)
35
+ end
36
+
37
+ def error(msg)
38
+ @shell.say(msg, :red)
39
+ end
40
+ end
41
+
42
+ class RGProxy < Gem::SilentUI
43
+ def initialize(ui)
44
+ @ui = ui
45
+ end
46
+
47
+ def say(message)
48
+ if message =~ /native extensions/
49
+ @ui.info "with native extensions "
50
+ else
51
+ @ui.debug(message)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,15 @@
1
+ module YourApp #:nodoc: all
2
+ VERSION = "0.1.0"
3
+
4
+ ##
5
+ # mix the ThorCheese module into your base nameespace. This allows you to boot an
6
+ # instance of the colourful Cheese::UI::Sheel
7
+ #
8
+ include Thor::Cheese
9
+
10
+ ##
11
+ # Example error-extension
12
+ #
13
+ class Error < Thor::Cheese::Error; status_code(666) ; end
14
+
15
+ end
@@ -0,0 +1,36 @@
1
+ ##
2
+ # Example Thor instance
3
+ #
4
+ module YourApp
5
+ class CLI < Thor
6
+
7
+ desc "say", "Say cheese and receive"
8
+ def say(word)
9
+ if word == 'cheese'
10
+ YourApp.ui.confirm("CHEESE!")
11
+ YourApp.ui.warn("------ -- -- ------ ------ ------ ------")
12
+ YourApp.ui.warn("-- -- -- -- -- -- --")
13
+ YourApp.ui.warn("-- ------ ---- ---- ------ ----")
14
+ YourApp.ui.warn("-- -- -- -- -- -- --")
15
+ YourApp.ui.warn("------ -- -- ------ ------ ------ ------")
16
+
17
+ else
18
+ YourApp.ui.error("------------------------------------------")
19
+ YourApp.ui.error("\"#{word}\"?? No cheese for you :(")
20
+ YourApp.ui.error("------------------------------------------")
21
+ end
22
+ end
23
+
24
+ ##
25
+ # For your convenience, override initialize and boot an instance of XCLI::UI::Shell by sending your
26
+ # shell method mixed-in by Cheese.
27
+ # YourApp.ui.confirm("That was good cheese")
28
+ # YourApp.ui.warn("That's stinky cheese")
29
+ # YourApp.ui.error("That was horrible cheese")
30
+ #
31
+ def initialize(*)
32
+ YourApp.shell = shell
33
+ super
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'xcli'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestXcli < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{thor-cheese}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Christocracy"]
12
+ s.date = %q{2010-03-11}
13
+ s.default_executable = %q{thor-cheese}
14
+ s.description = %q{General Thor extension for building console-based ruby apps with built-in colour UI}
15
+ s.email = %q{christocracy@gmail.com}
16
+ s.executables = ["thor-cheese"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/thor-cheese",
29
+ "lib/thor-cheese.rb",
30
+ "lib/thor-cheese/ui.rb",
31
+ "lib/your-app.rb",
32
+ "lib/your-app/cli.rb",
33
+ "test/helper.rb",
34
+ "test/test_xcli.rb",
35
+ "thor-cheese.gemspec"
36
+ ]
37
+ s.homepage = %q{http://github.com/christocracy/thor-cheese}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.6}
41
+ s.summary = %q{General Thor extension for building console-based ruby apps. Has built-in colour UI}
42
+ s.test_files = [
43
+ "test/helper.rb",
44
+ "test/test_xcli.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ s.add_runtime_dependency(%q<thor>, [">= 0.13.0"])
53
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ else
55
+ s.add_dependency(%q<thor>, [">= 0.13.0"])
56
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<thor>, [">= 0.13.0"])
60
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
61
+ end
62
+ end
63
+
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thor-cheese
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Christocracy
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-11 00:00:00 -05:00
18
+ default_executable: thor-cheese
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thor
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 13
30
+ - 0
31
+ version: 0.13.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: thoughtbot-shoulda
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: General Thor extension for building console-based ruby apps with built-in colour UI
47
+ email: christocracy@gmail.com
48
+ executables:
49
+ - thor-cheese
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.rdoc
55
+ files:
56
+ - .document
57
+ - .gitignore
58
+ - LICENSE
59
+ - README.rdoc
60
+ - Rakefile
61
+ - VERSION
62
+ - bin/thor-cheese
63
+ - lib/thor-cheese.rb
64
+ - lib/thor-cheese/ui.rb
65
+ - lib/your-app.rb
66
+ - lib/your-app/cli.rb
67
+ - test/helper.rb
68
+ - test/test_xcli.rb
69
+ - thor-cheese.gemspec
70
+ has_rdoc: true
71
+ homepage: http://github.com/christocracy/thor-cheese
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options:
76
+ - --charset=UTF-8
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.3.6
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: General Thor extension for building console-based ruby apps. Has built-in colour UI
100
+ test_files:
101
+ - test/helper.rb
102
+ - test/test_xcli.rb