simpleconsole 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/files/full.rb +17 -0
- data/bin/simcon +10 -4
- data/lib/application.rb +1 -1
- data/lib/controller.rb +6 -3
- data/lib/helper.rb +19 -0
- data/lib/init.rb +2 -0
- data/lib/prompter.rb +2 -0
- data/lib/simpleconsole.rb +2 -0
- data/test/test_prompter.rb +8 -0
- metadata +7 -2
data/bin/files/full.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
require "rubygems"
|
3
|
+
require "simpleconsole"
|
4
|
+
# require File.dirname(__FILE__) + "/../"
|
5
|
+
|
6
|
+
class _Controller_ < SimpleConsole::Controller
|
7
|
+
def default
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(method)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class _View_ < SimpleConsole::View
|
15
|
+
end
|
16
|
+
|
17
|
+
SimpleConsole::Application.run(ARGV, _Controller_, _View_)
|
data/bin/simcon
CHANGED
@@ -7,8 +7,8 @@ class Controller < SimpleConsole::Controller
|
|
7
7
|
params :string => {:c => :controller, :v => :view, :f => :file},
|
8
8
|
:bool => {:h => :help}
|
9
9
|
before_filter :check_params
|
10
|
-
before_filter :set_file, :only => [:application, :controller, :single, :view]
|
11
|
-
after_filter :put_file, :only => [:application, :controller, :single, :view]
|
10
|
+
before_filter :set_file, :only => [:application, :controller, :single, :full, :view]
|
11
|
+
after_filter :put_file, :only => [:application, :controller, :single, :full, :view]
|
12
12
|
|
13
13
|
def rakefile
|
14
14
|
@filename = "Rakefile"
|
@@ -21,7 +21,7 @@ class Controller < SimpleConsole::Controller
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def help
|
24
|
-
generators = [:application, :controller, :rakefile, :single, :view]
|
24
|
+
generators = [:application, :controller, :full, :rakefile, :single, :view]
|
25
25
|
unless params[:id].nil?
|
26
26
|
redirect_to(:action => ("help_" + params[:id]).to_sym) if generators.include?(params[:id].to_sym)
|
27
27
|
render :action => :unknown_help
|
@@ -108,7 +108,7 @@ class View < SimpleConsole::View
|
|
108
108
|
puts " single [--file output_file] [-c controller_name | -v view_name]"
|
109
109
|
puts " view [--file output_file] [-v view_name]"
|
110
110
|
puts ""
|
111
|
-
puts "The generators will create a new file given by the '-f output_file' argument. If no '--file' was given, it will output to STDOUT. Try '
|
111
|
+
puts "The generators will create a new file given by the '-f output_file' argument. If no '--file' was given, it will output to STDOUT. Try 'simcon help [generator]' for more info about each generator."
|
112
112
|
puts ""
|
113
113
|
puts "Available options:"
|
114
114
|
puts " -f | --file FILENAME"
|
@@ -138,6 +138,12 @@ class View < SimpleConsole::View
|
|
138
138
|
puts "Generates an entire application within a single script, including the Controller/View classes and the Application.run statement."
|
139
139
|
end
|
140
140
|
|
141
|
+
def help_full
|
142
|
+
puts "Usage simcon full [-f output_file] [-c controller_name | -v view_name]"
|
143
|
+
puts ""
|
144
|
+
puts "Generates an entire application within a single script, including the Controller/View classes and the Application.run statement. Also generates the method_missing and default methods."
|
145
|
+
end
|
146
|
+
|
141
147
|
def help_view
|
142
148
|
puts "Usage simcon view [-f output_file] [-v view_name]"
|
143
149
|
puts ""
|
data/lib/application.rb
CHANGED
@@ -37,7 +37,7 @@ class SimpleConsole::Application
|
|
37
37
|
@@control = controller_klass.new
|
38
38
|
@@view = view_klass ? view_klass.new(@@control) : nil
|
39
39
|
@@control.set_params(argv)
|
40
|
-
@@control.set_action(argv[0] || :default)
|
40
|
+
@@control.set_action(argv[0] =~ /^-/ ? :default : argv[0] || :default)
|
41
41
|
|
42
42
|
@@control.execute_action
|
43
43
|
@@view.render_action unless @@view.nil?
|
data/lib/controller.rb
CHANGED
@@ -25,7 +25,7 @@ require File.dirname(__FILE__) + "/filter.rb"
|
|
25
25
|
# Check out the "before_filter" and "after_filter" methods, similar to the
|
26
26
|
# methods implemented in Rails.
|
27
27
|
class SimpleConsole::Controller
|
28
|
-
attr_accessor :params
|
28
|
+
attr_accessor :params, :argv
|
29
29
|
|
30
30
|
# Filter for methods to call previous to an action
|
31
31
|
@@before_chain = SimpleConsole::Filter.new
|
@@ -35,11 +35,12 @@ class SimpleConsole::Controller
|
|
35
35
|
|
36
36
|
# Keeps track of param types
|
37
37
|
@@params_parser = SimpleConsole::ParamsParser.new
|
38
|
-
|
38
|
+
|
39
39
|
# Initializes the "params" hash and creates a new Controller. Not needed when
|
40
40
|
# developing an application with SimpleConsole.
|
41
41
|
def initialize()
|
42
42
|
@params = Hash.new
|
43
|
+
@argv = Array.new
|
43
44
|
end
|
44
45
|
|
45
46
|
# Returns true if the controller defines the action given, otherwise returns
|
@@ -64,6 +65,7 @@ class SimpleConsole::Controller
|
|
64
65
|
params[:id] = id.to_i
|
65
66
|
end
|
66
67
|
params.update(@@params_parser.argv_to_params(argv))
|
68
|
+
argv.concat(argv)
|
67
69
|
end
|
68
70
|
|
69
71
|
# Sets the current action to the new action parameter.
|
@@ -85,7 +87,7 @@ class SimpleConsole::Controller
|
|
85
87
|
raise error unless error.message == "Simple::Console Redirection"
|
86
88
|
end
|
87
89
|
end
|
88
|
-
|
90
|
+
|
89
91
|
protected
|
90
92
|
# When the view is rendered, this action is used instead
|
91
93
|
# == Example Usage
|
@@ -219,4 +221,5 @@ class SimpleConsole::Controller
|
|
219
221
|
|
220
222
|
# block all of these methods from being controller actions
|
221
223
|
@@block_action = self.new.methods
|
224
|
+
|
222
225
|
end
|
data/lib/helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module SimpleConsole::TestHelper
|
2
|
+
def run(action, params)
|
3
|
+
@control.params = params
|
4
|
+
SimpleConsole::Application.run([action.to_sym], @control, @view)
|
5
|
+
end
|
6
|
+
|
7
|
+
def output
|
8
|
+
return @output.string
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize_data
|
12
|
+
@control.instance_variables.each do |var|
|
13
|
+
define_method(var.to_s.gsub("^@", "")) do
|
14
|
+
return @control.instance_variable_get(var)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/init.rb
CHANGED
data/lib/prompter.rb
ADDED
data/lib/simpleconsole.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: simpleconsole
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date:
|
6
|
+
version: 0.1.1
|
7
|
+
date: 2007-01-16 00:00:00 -08:00
|
8
8
|
summary: Microframework for developing console apps quickly.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- bin/simcon
|
34
34
|
- bin/files/application.rb
|
35
35
|
- bin/files/controller.rb
|
36
|
+
- bin/files/full.rb
|
36
37
|
- bin/files/Rakefile
|
37
38
|
- bin/files/single.rb
|
38
39
|
- bin/files/view.rb
|
@@ -41,12 +42,15 @@ files:
|
|
41
42
|
- test/test_filter.rb
|
42
43
|
- test/test_init.rb
|
43
44
|
- test/test_params_parser.rb
|
45
|
+
- test/test_prompter.rb
|
44
46
|
- test/test_view.rb
|
45
47
|
- lib/application.rb
|
46
48
|
- lib/controller.rb
|
47
49
|
- lib/filter.rb
|
50
|
+
- lib/helper.rb
|
48
51
|
- lib/init.rb
|
49
52
|
- lib/params_parser.rb
|
53
|
+
- lib/prompter.rb
|
50
54
|
- lib/simpleconsole.rb
|
51
55
|
- lib/view.rb
|
52
56
|
- README
|
@@ -57,6 +61,7 @@ test_files:
|
|
57
61
|
- test/test_filter.rb
|
58
62
|
- test/test_init.rb
|
59
63
|
- test/test_params_parser.rb
|
64
|
+
- test/test_prompter.rb
|
60
65
|
- test/test_view.rb
|
61
66
|
rdoc_options: []
|
62
67
|
|