scrawler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in scrawler.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/scrawl ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'scrawler'
7
+ require 'scrawler/command'
8
+
9
+ args = ARGV.dup
10
+ ARGV.clear
11
+ command = args.shift.strip rescue 'help'
12
+
13
+ Scrawler::Command.run(command, args)
data/lib/scrawler.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Scrawler
2
+ # Your code goes here...
3
+ end
@@ -0,0 +1,56 @@
1
+ require 'scrawler/helpers'
2
+ require 'scrawler/commands/base'
3
+
4
+ Dir["#{File.dirname(__FILE__)}/commands/*.rb"].each { |c| require c }
5
+
6
+ module Scrawler
7
+ module Command
8
+ class InvalidCommand < RuntimeError; end
9
+ class CommandFailed < RuntimeError; end
10
+
11
+ extend Scrawler::Helpers
12
+
13
+ class << self
14
+
15
+ def run(command, args)
16
+ begin
17
+ run_internal(command, args.dup)
18
+ rescue InvalidCommand
19
+ error "Unknown command. Run 'scrawl help' for usage information."
20
+ rescue CommandFailed => e
21
+ error e.message
22
+ rescue Interrupt => e
23
+ error "\n[canceled]"
24
+ end
25
+ end
26
+
27
+ def run_internal(command, args)
28
+ klass, method = parse(command)
29
+ runner = klass.new(args)
30
+ raise InvalidCommand unless runner.respond_to?(method)
31
+ runner.send(method)
32
+ end
33
+
34
+ def parse(command)
35
+ parts = command.split(':')
36
+ case parts.size
37
+ when 1
38
+ begin
39
+ return eval("Scrawler::Command::#{command.capitalize}"), :index
40
+ rescue NameError, NoMethodError
41
+ return Scrawler::Command::App, command.to_sym
42
+ end
43
+ else
44
+ begin
45
+ const = Scrawler::Command
46
+ command = parts.pop
47
+ parts.each { |part| const = const.const_get(part.capitalize) }
48
+ return const, command.to_sym
49
+ rescue NameError
50
+ raise InvalidCommand
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,32 @@
1
+ module Scrawler::Command
2
+ class App < Base
3
+ def create
4
+ template = extract_option('--template', 'default')
5
+ template = "default" if template.nil?
6
+ pages = (extract_option('--pages', '') || '').split(',')
7
+ name = args.shift.downcase.strip rescue nil
8
+
9
+ display("Creating #{name}...", false)
10
+
11
+ current_path = FileUtils.pwd
12
+
13
+ template_path = File.expand_path("../../templates/#{template}", __FILE__)
14
+ template_path = File.expand_path(".scrawler/templates/#{template}", home_directory) unless Dir.exist?(template_path)
15
+ error "The \"#{template}\" template does not exists." unless Dir.exist?(template_path)
16
+
17
+ FileUtils.mkdir(name)
18
+ display(".", false)
19
+
20
+ Dir["#{template_path}/*"].each do |c|
21
+ FileUtils.cp(c, "#{current_path}/#{name}/#{File.basename(c)}")
22
+ display(".", false)
23
+ end
24
+
25
+ pages.each do |page|
26
+ FileUtils.touch("#{current_path}/#{name}/#{page}")
27
+ end
28
+
29
+ display " done"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ require 'fileutils'
2
+
3
+ module Scrawler::Command
4
+ class Base
5
+ include Scrawler::Helpers
6
+
7
+ attr_accessor :args
8
+
9
+ def initialize(args)
10
+ @args = args
11
+ end
12
+
13
+ def extract_option(options, default=true)
14
+ values = options.is_a?(Array) ? options : [options]
15
+ return unless opt_index = args.select { |a| values.include? a }.first
16
+ opt_position = args.index(opt_index) + 1
17
+ if args.size > opt_position && opt_value = args[opt_position]
18
+ if opt_value.include?('--')
19
+ opt_value = nil
20
+ else
21
+ args.delete_at(opt_position)
22
+ end
23
+ end
24
+ opt_value ||= default
25
+ args.delete(opt_index)
26
+ block_given? ? yield(opt_value) : opt_value
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ module Scrawler::Command
2
+ class Help < Base
3
+ def index
4
+ display "Comming soon"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,56 @@
1
+ module Scrawler
2
+ module Helpers
3
+ def home_directory
4
+ running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
5
+ end
6
+
7
+ def running_on_windows?
8
+ RUBY_PLATFORM =~ /mswin32|mingw32/
9
+ end
10
+
11
+ def running_on_a_mac?
12
+ RUBY_PLATFORM =~ /-darwin\d/
13
+ end
14
+
15
+ def display(msg, newline=true)
16
+ if newline
17
+ puts(msg)
18
+ else
19
+ print(msg)
20
+ STDOUT.flush
21
+ end
22
+ end
23
+
24
+ def redisplay(line, line_break = false)
25
+ display("\r\e[0K#{line}", line_break)
26
+ end
27
+
28
+ def deprecate(version)
29
+ display "!!! DEPRECATION WARNING: This command will be removed in version #{version}"
30
+ display ""
31
+ end
32
+
33
+ def error(msg)
34
+ STDERR.puts(msg)
35
+ exit 1
36
+ end
37
+
38
+ def confirm(message="Are you sure you wish to continue? (y/n)?")
39
+ display("#{message} ", false)
40
+ ask.downcase == 'y'
41
+ end
42
+
43
+ def format_date(date)
44
+ date = Time.parse(date) if date.is_a?(String)
45
+ date.strftime("%Y-%m-%d %H:%M %Z")
46
+ end
47
+
48
+ def ask
49
+ gets.strip
50
+ end
51
+
52
+ def run_command(command, args=[])
53
+ Scrawler::Command.run_internal(command, args)
54
+ end
55
+ end
56
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ module Scrawler
2
+ VERSION = "0.0.1"
3
+ end
data/scrawler.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "scrawler/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "scrawler"
7
+ s.version = Scrawler::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Daniel Spangenberg"]
10
+ s.email = ["daniel.spangenberg@parcydo.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Project management framework.}
13
+ s.description = %q{Scrawler is a project management framework optimized for programmer happiness and sustainable productivity.}
14
+
15
+ s.rubyforge_project = "scrawler"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scrawler
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Spangenberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-24 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Scrawler is a project management framework optimized for programmer happiness and sustainable productivity.
18
+ email:
19
+ - daniel.spangenberg@parcydo.com
20
+ executables:
21
+ - scrawl
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - .gitignore
28
+ - Gemfile
29
+ - Rakefile
30
+ - bin/scrawl
31
+ - lib/scrawler.rb
32
+ - lib/scrawler/command.rb
33
+ - lib/scrawler/commands/app.rb
34
+ - lib/scrawler/commands/base.rb
35
+ - lib/scrawler/commands/help.rb
36
+ - lib/scrawler/helpers.rb
37
+ - lib/scrawler/templates/default/general
38
+ - lib/scrawler/version.rb
39
+ - scrawler.gemspec
40
+ has_rdoc: true
41
+ homepage: ""
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project: scrawler
64
+ rubygems_version: 1.5.0
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Project management framework.
68
+ test_files: []
69
+