hawknee 0.2.0 → 0.2.1

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.
@@ -1,3 +1,9 @@
1
+ = hawknee 0.2.1 (07-03-2011)
2
+
3
+ - Routes are now working! (I mean, this '/forum' scope works!)
4
+ - Yay! ARGV.first now working as a command!
5
+ - Added the hawknee:install generator. Now it's not working, but it will be in next versions.
6
+
1
7
  = hawknee 0.2.0 (06-03-2011)
2
8
 
3
9
  - Birthday!
@@ -8,6 +8,11 @@ Hawknee is a gem that implements a forum, to your Rails 3.0 app.
8
8
 
9
9
  gem install hawknee
10
10
 
11
+ or get the .gem package from {here}[https://rubygems.org/gems/hawknee] and type
12
+
13
+ cd /directory/where/the/.gem/file/is
14
+ gem install hawknee-x.y.z.gem
15
+
11
16
  2. Then, to install the forum:
12
17
 
13
18
  cd /path/to/your/rails/app/path # Go to your Rails app
@@ -21,7 +26,6 @@ Hawknee is a gem that implements a forum, to your Rails 3.0 app.
21
26
  Hawknee uses:
22
27
 
23
28
  - rails >= 3.0.0
24
- - haml >= 3.0.25
25
29
 
26
30
  == Contributing to Hawknee
27
31
 
@@ -0,0 +1,5 @@
1
+ module Hawknee
2
+ class ApplicationController < ::ApplicationController
3
+
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module Hawknee
2
+ class MainController < Hawknee::ApplicationController
3
+
4
+ # GET /forum
5
+ def index
6
+ respond_to do |format|
7
+ format.html { render :layout => 'hawknee/application' }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ <h1>Aye!</h1>
2
+ <p>We're on a board, comrade!</p>
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Hawknee</title>
5
+ </head>
6
+ <body>
7
+ <%= yield %>
8
+ </body>
9
+ </html>
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Add the lib directory to $LOAD_PATH
4
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
5
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
6
+
7
+ # Require needed files
8
+ require 'hawknee'
9
+ require 'hawknee/cli'
10
+
11
+ # We make the --help option the default (if no command passed, show help)
12
+ ARGV << '--help' if ARGV.empty? && $stdin.tty?
13
+
14
+ # Run!
15
+ Hawknee::Cli.new(ARGV)
@@ -0,0 +1,7 @@
1
+ Rails.application.routes.draw do
2
+ scope "forum", :module => :hawknee, :as => "hawknee" do
3
+ controller "main" do
4
+ match "/", :to => :index, :as => "portal"
5
+ end
6
+ end
7
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'hawknee'
@@ -0,0 +1,10 @@
1
+ module Hawknee
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ class_option :path, :type => :string, :default => "#{Dir.pwd}", :desc => "Sepcifies the directory where the app, you want to install Hawknee in, lives."
5
+
6
+ def manifest
7
+ puts "Welllcome to Hawknee installation script, stranger!\n\nInstallation to #{options[:path]}"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ require 'hawknee/engine' if defined? Rails && Rails::VERSION::MAJOR == 3
2
+
3
+ module Hawknee; end
@@ -0,0 +1,106 @@
1
+ # For nice --options parsing
2
+ require 'optparse'
3
+
4
+ # Require some needed files
5
+ require 'hawknee/version'
6
+ require 'hawknee/colors'
7
+ require 'hawknee/helpers'
8
+
9
+ # For nice 'n' clean code
10
+ include Hawknee::Helpers
11
+
12
+ module Hawknee
13
+
14
+ # You know.. Command Line Interface.. Got it? :)
15
+ class Cli
16
+
17
+ # Command classes inherit from this module, so we keep command class names separatly with classes somewhere in code.
18
+ # In other words.. Only class which inherits from Hawknee::Cli::Command can be a command.
19
+ module Command
20
+ Dir["#{File.dirname(__FILE__)}/commands/*.rb"].each { |f| require f }
21
+ end
22
+
23
+ # Initialize new Cli, and.. here we go!
24
+ #
25
+ # some enlightening:
26
+ #
27
+ # @command - ARGV.first
28
+ # @options - simple opts handler
29
+ #
30
+ def initialize(*args)
31
+
32
+ # Handles options
33
+ @options = {}
34
+
35
+ # Set up the command and subcommand
36
+ @command, @subcommand = parse_command
37
+
38
+ begin
39
+ opts = OptionParser.new do |opts|
40
+ opts.banner = "Usage: hawknee COMMAND [OPTIONS]"
41
+
42
+ opts.separator " "
43
+
44
+ opts.separator "Installing Hawknee:"
45
+ opts.separator " rails new app_name # Make new Rails application"
46
+ opts.separator " cd app_name # Switch to the app's directory"
47
+ opts.separator " gedit Gemfile # Add: gem 'hawknee', '#{Hawknee::Version::STRING}'"
48
+ opts.separator " rails generate hawknee:install # Copies needed files"
49
+ opts.separator " rails server # Runs the server"
50
+ opts.separator " go to http://localhost:3000/forum"
51
+ opts.separator " "
52
+ opts.separator " Have fun!"
53
+
54
+ opts.separator " "
55
+
56
+ opts.separator "Common options:"
57
+ opts.on('-v', '--version', 'Show version') do
58
+ puts "Hawknee " + Hawknee::Version::STRING
59
+ exit
60
+ end
61
+
62
+ opts.on('-h', '--help', 'Display this message') do
63
+ puts opts
64
+ exit
65
+ end
66
+ end.parse!
67
+ rescue OptionParser::InvalidOption => e
68
+ raise BadOption
69
+ end
70
+
71
+ # Here, in Hawknee, commands are simply classes, (kept in files in 'commands' directory) that inherits from Hawknee::Cli::Command.
72
+ # To see it in action, dig a bit in lib/commands/new.rb file
73
+ #
74
+ begin
75
+ # We make sure the command (class) exists.
76
+ run if command_exists?
77
+ # When user typed some class (command) that doesn't exists.
78
+ rescue BadCommand => e
79
+ puts e.message
80
+ # When typed ^C
81
+ rescue Interrupt
82
+ puts "\n[" + "interrupted".bold.colorize(:red) + "]"
83
+ end
84
+
85
+ end # initialize
86
+
87
+ def run
88
+ begin
89
+ eval "Hawknee::Cli::Command::#{@command.capitalize}.new.#{@subcommand}"
90
+ rescue NameError, NoMethodError
91
+ raise BadCommand
92
+ end
93
+ end # run
94
+
95
+ def parse_command
96
+ case ARGV.length
97
+ when 1
98
+ return ARGV.first.to_s, 'init'
99
+ when 2
100
+ if ARGV[1] != nil
101
+ return ARGV.first.to_s, ARGV[1].to_s
102
+ end
103
+ end
104
+ end
105
+ end # Cli
106
+ end # Hawknee
@@ -0,0 +1,75 @@
1
+ module Hawknee
2
+
3
+ # Effects for lines in terminal
4
+ Effects = {
5
+ :clear => "\e[0m",
6
+ :bold => "\e[1m",
7
+
8
+ :underline => "\e[4m",
9
+ :blink => "\e[5m",
10
+ :reverse => "\e[7m",
11
+ :hide => "\e[8m",
12
+ }
13
+
14
+ # Colors for lines in terminal
15
+ Colors = {
16
+ :black => "\e[30m",
17
+ :red => "\e[31m",
18
+ :green => "\e[32m",
19
+ :yellow => "\e[33m",
20
+ :blue => "\e[34m",
21
+ :magenta => "\e[35m",
22
+ :cyan => "\e[36m",
23
+ :white => "\e[37m",
24
+ :default => "\e[39m",
25
+
26
+ :on_black => "\e[40m",
27
+ :on_red => "\e[41m",
28
+ :on_green => "\e[42m",
29
+ :on_yellow => "\e[43m",
30
+ :on_blue => "\e[44m",
31
+ :on_magenta => "\e[45m",
32
+ :on_cyan => "\e[46m",
33
+ :on_white => "\e[47m",
34
+ :on_default => "\e[49m",
35
+ }
36
+ end
37
+
38
+ class String
39
+
40
+ # Colorizes a string
41
+ def colorize(symbol)
42
+ string = self
43
+ "#{Hawknee::Colors[symbol.downcase.to_sym]}#{string}#{Hawknee::Effects[:clear]}"
44
+ end
45
+
46
+ # Makes a string bold
47
+ def bold
48
+ string = self
49
+ "#{Hawknee::Effects[:bold]}#{string}#{Hawknee::Effects[:clear]}"
50
+ end
51
+
52
+ # Hides a string
53
+ def hide
54
+ string = self
55
+ "#{Hawknee::Effects[:hide]}#{string}#{Hawknee::Effects[:clear]}"
56
+ end
57
+
58
+ # Underlines a string
59
+ def underline
60
+ string = self
61
+ "#{Hawknee::Effects[:underline]}#{string}#{Hawknee::Effects[:clear]}"
62
+ end
63
+
64
+ # Reverses foreground and background colors
65
+ def reverse
66
+ string = self
67
+ "#{Hawknee::Effects[:reverse]}#{string}#{Hawknee::Effects[:clear]}"
68
+ end
69
+
70
+ # To be honest.. Dunno what this does :D
71
+ def blink
72
+ string = self
73
+ "#{Hawknee::Effects[:blink]}#{string}#{Hawknee::Effects[:clear]}"
74
+ end
75
+ end
@@ -0,0 +1,15 @@
1
+ module Hawknee::Cli::Command
2
+ class New
3
+ def init
4
+ puts "New fired up!"
5
+ end
6
+
7
+ def topic
8
+ puts "New topic fired up!"
9
+ end
10
+
11
+ def forum
12
+ puts "New forum fired up!"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ require 'rails'
2
+
3
+ module Hawknee
4
+ class Engine < Rails::Engine
5
+ engine_name :hawknee
6
+ paths.config.routes = "config/routes.rb"
7
+ end
8
+ end
@@ -0,0 +1,52 @@
1
+ module Hawknee::Helpers
2
+ extend self
3
+
4
+ def ask(what)
5
+ print what
6
+ $stdin.gets.chomp.strip
7
+ end
8
+
9
+ # Ask user if he wants to do something. If he passed 'n' it exits.
10
+ #
11
+ # usage examples:
12
+ #
13
+ # confirm? # Puts "Are you sure to continue? (y/n): ", and waits for input
14
+ # confirm? "Delete?" # Puts "Delete? (y/n): ", and waits for input
15
+ # puts "Confirmed" if confirm? # Puts "Confirmed" if user passed 'y'
16
+ #
17
+ def confirm?(what = "Are you sure to continue?")
18
+ print what + " (y/n): " # Hmmm... DRY? Yeah. DRY. We keep ourselves before writing (y/n): several times.
19
+ if $stdin.gets.chomp.strip =~ /y/i then true else exit end # Exit if input != y
20
+ end
21
+
22
+ # Used to check if command user passed exists. If not, raises BadCommand, and shows appropriate note.
23
+ #
24
+ # usage examples:
25
+ #
26
+ # puts "Good" if command_exists? 'initialize'
27
+ #
28
+ def command_exists?
29
+ begin
30
+ true if eval "Hawknee::Cli::Command::#{@command.capitalize}.new"
31
+ rescue NameError
32
+ raise BadCommand
33
+ end
34
+ end
35
+
36
+ ### Exceptions/errors down here
37
+ class BadOption < RuntimeError
38
+ def initialize
39
+ puts "Ooops!".bold.colorize(:red) + " It seems, you passed invalid option"
40
+ puts "Run with " + "-h".bold.colorize(:blue) + " or " + "--help".bold.colorize(:blue) + " option, to get some help."
41
+ exit
42
+ end
43
+ end
44
+
45
+ class BadCommand < RuntimeError
46
+ def initialize
47
+ puts "Ooops!".bold.colorize(:red) + " It seems, you typed some invalid command"
48
+ puts "Run with " + "-h".bold.colorize(:blue) + " or " + "--help".bold.colorize(:blue) + " option, to get some help."
49
+ exit
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hawknee
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Szymon Urba\xC5\x9B"
@@ -10,8 +10,8 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-06 00:00:00 +01:00
14
- default_executable:
13
+ date: 2011-03-20 00:00:00 +01:00
14
+ default_executable: hawknee
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: shoulda
@@ -59,23 +59,31 @@ dependencies:
59
59
  version_requirements: *id004
60
60
  description: Easily implement a forum to your Rails 3 application.
61
61
  email: szymon.urbas@yahoo.com
62
- executables: []
63
-
62
+ executables:
63
+ - hawknee
64
64
  extensions: []
65
65
 
66
66
  extra_rdoc_files:
67
67
  - LICENSE.txt
68
68
  - README.rdoc
69
69
  files:
70
- - .document
71
70
  - CHANGELOG.rdoc
72
- - Gemfile
73
- - Gemfile.lock
74
71
  - LICENSE.txt
75
72
  - README.rdoc
76
- - Rakefile
77
- - hawknee.gemspec
73
+ - app/controllers/hawknee/application_controller.rb
74
+ - app/controllers/hawknee/main_controller.rb
75
+ - app/views/hawknee/main/index.html.erb
76
+ - app/views/layouts/hawknee/application.html.erb
77
+ - bin/hawknee
78
+ - config/routes.rb
79
+ - init.rb
80
+ - lib/generators/hawknee/install/install_generator.rb
78
81
  - lib/hawknee.rb
82
+ - lib/hawknee/cli.rb
83
+ - lib/hawknee/colors.rb
84
+ - lib/hawknee/commands/new.rb
85
+ - lib/hawknee/engine.rb
86
+ - lib/hawknee/helpers.rb
79
87
  - lib/hawknee/version.rb
80
88
  - test/helper.rb
81
89
  - test/test_hawknee.rb
@@ -93,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
101
  requirements:
94
102
  - - ">="
95
103
  - !ruby/object:Gem::Version
96
- hash: 281582899
104
+ hash: -718481523
97
105
  segments:
98
106
  - 0
99
107
  version: "0"
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/Gemfile DELETED
@@ -1,13 +0,0 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "shoulda", ">= 0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.5.2"
12
- gem "rcov", ">= 0"
13
- end
@@ -1,20 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- git (1.2.5)
5
- jeweler (1.5.2)
6
- bundler (~> 1.0.0)
7
- git (>= 1.2.5)
8
- rake
9
- rake (0.8.7)
10
- rcov (0.9.9)
11
- shoulda (2.11.3)
12
-
13
- PLATFORMS
14
- ruby
15
-
16
- DEPENDENCIES
17
- bundler (~> 1.0.0)
18
- jeweler (~> 1.5.2)
19
- rcov
20
- shoulda
data/Rakefile DELETED
@@ -1,57 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require './lib/hawknee/version'
4
- require 'rubygems'
5
- require 'bundler'
6
- begin
7
- Bundler.setup(:default, :development)
8
- rescue Bundler::BundlerError => e
9
- $stderr.puts e.message
10
- $stderr.puts "Run `bundle install` to install missing gems"
11
- exit e.status_code
12
- end
13
- require 'rake'
14
-
15
- require 'jeweler'
16
- Jeweler::Tasks.new do |gem|
17
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
- gem.name = "hawknee"
19
- gem.version = Hawknee::Version::STRING
20
- gem.homepage = "http://github.com/semahawk/hawknee"
21
- gem.license = "MIT"
22
- gem.summary = %Q{Ruby on Rails 3 based forum.}
23
- gem.description = %Q{Easily implement a forum to your Rails 3 application.}
24
- gem.email = "szymon.urbas@yahoo.com"
25
- gem.authors = ["Szymon Urbaś"]
26
- # Include your dependencies below. Runtime dependencies are required when using your gem,
27
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
28
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
29
- # gem.add_development_dependency 'rspec', '> 1.2.3'
30
- end
31
- Jeweler::RubygemsDotOrgTasks.new
32
-
33
- require 'rake/testtask'
34
- Rake::TestTask.new(:test) do |test|
35
- test.libs << 'lib' << 'test'
36
- test.pattern = 'test/**/test_*.rb'
37
- test.verbose = true
38
- end
39
-
40
- require 'rcov/rcovtask'
41
- Rcov::RcovTask.new do |test|
42
- test.libs << 'test'
43
- test.pattern = 'test/**/test_*.rb'
44
- test.verbose = true
45
- end
46
-
47
- task :default => :test
48
-
49
- require 'rake/rdoctask'
50
- Rake::RDocTask.new do |rdoc|
51
- version = Hawknee::Version::STRING
52
-
53
- rdoc.rdoc_dir = 'rdoc'
54
- rdoc.title = "Hawknee #{version}"
55
- rdoc.rdoc_files.include('README*')
56
- rdoc.rdoc_files.include('lib/**/*.rb')
57
- end
@@ -1,64 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{hawknee}
8
- s.version = "0.2.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Szymon Urbaś"]
12
- s.date = %q{2011-03-06}
13
- s.description = %q{Easily implement a forum to your Rails 3 application.}
14
- s.email = %q{szymon.urbas@yahoo.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE.txt",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- "CHANGELOG.rdoc",
22
- "Gemfile",
23
- "Gemfile.lock",
24
- "LICENSE.txt",
25
- "README.rdoc",
26
- "Rakefile",
27
- "hawknee.gemspec",
28
- "lib/hawknee.rb",
29
- "lib/hawknee/version.rb",
30
- "test/helper.rb",
31
- "test/test_hawknee.rb"
32
- ]
33
- s.homepage = %q{http://github.com/semahawk/hawknee}
34
- s.licenses = ["MIT"]
35
- s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.5.2}
37
- s.summary = %q{Ruby on Rails 3 based forum.}
38
- s.test_files = [
39
- "test/helper.rb",
40
- "test/test_hawknee.rb"
41
- ]
42
-
43
- if s.respond_to? :specification_version then
44
- s.specification_version = 3
45
-
46
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- s.add_development_dependency(%q<shoulda>, [">= 0"])
48
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
50
- s.add_development_dependency(%q<rcov>, [">= 0"])
51
- else
52
- s.add_dependency(%q<shoulda>, [">= 0"])
53
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
55
- s.add_dependency(%q<rcov>, [">= 0"])
56
- end
57
- else
58
- s.add_dependency(%q<shoulda>, [">= 0"])
59
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
61
- s.add_dependency(%q<rcov>, [">= 0"])
62
- end
63
- end
64
-