webcli 0.0.2

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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Eduardo Del Balso
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.
data/README.rdoc ADDED
@@ -0,0 +1,25 @@
1
+ = webcli
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (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)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Built According To
16
+
17
+ http://www.themodestrubyist.com/2010/03/01/rails-3-plugins---part-1---the-big-picture/
18
+ http://www.themodestrubyist.com/2010/03/05/rails-3-plugins---part-2---writing-an-engine/
19
+ http://www.themodestrubyist.com/2010/03/16/rails-3-plugins---part-3---rake-tasks-generators-initializers-oh-my/
20
+ http://www.themodestrubyist.com/2010/03/22/rails-3-plugins---part-4---more-on-generators/
21
+
22
+
23
+ == Copyright
24
+
25
+ Copyright (c) 2010 Eduardo Del Balso. See LICENSE for details.
@@ -0,0 +1,76 @@
1
+ module Webcli
2
+ class CommandsController < ApplicationController
3
+
4
+ # unloadable
5
+
6
+ def run
7
+
8
+ puts File.join(RAILS_ROOT,'app','webcli-commands')
9
+ glob = File.join(RAILS_ROOT,'app','webcli-commands','*') # Rcli.script_root + DS + 'lib' + DS + 'commands' + DS + '*'
10
+
11
+ allowed_commands = []
12
+ Dir[glob].each{ |c| allowed_commands << File.basename(c,'.rb')}
13
+
14
+ puts allowed_commands.inspect
15
+
16
+ # user_input = params[:input]
17
+ # prev_command = params[:prev_cmd]
18
+ # input = nil
19
+
20
+ # if prev_command == ''
21
+ # command = user_input
22
+ # else
23
+ # command = prev_command
24
+ # input = user_input
25
+ # end
26
+
27
+ # unless allowed_commands.include?(command)
28
+ # json_reply = generate_reply('ERROR',"The command '#{command}' is invalid")
29
+ # else
30
+
31
+ # json_reply = nil
32
+
33
+ # puts "Received user command : '" + command + "'"
34
+
35
+ # if command == 'admin'
36
+ # json_reply = admin(input)
37
+ # else
38
+ # json_reply = {
39
+ # :status => "ERROR",
40
+ # :data => {
41
+ # :text => "'" + command + "' is an unrecognized Command",
42
+ # :url => nil
43
+ # }
44
+ # }
45
+ # end
46
+ # end
47
+
48
+ # respond_to do |format|
49
+ # format.html # index.html.erb
50
+ # format.json { render :json => json_reply.to_json }
51
+ # end
52
+
53
+ if allowed_commands.include?(params[:command])
54
+ require File.join(RAILS_ROOT,'app','webcli-commands',params[:command])
55
+ reply = Object.const_get( "#{params[:command].titleize}Command" ).send "reply"
56
+ else
57
+ reply = generate_reply("ERROR","TEXT",:text => "The command #{params[:command]} is invalid")
58
+ end
59
+
60
+ render :json => validate_reply(reply).to_json
61
+ end
62
+
63
+ private
64
+ def generate_reply(status = "ERROR",type = "TEXT", data = {}) #, text = nil, url = nil, prev_cmd = nil)
65
+ {
66
+ :status => status,
67
+ :type => type,
68
+ :data => data,
69
+ }
70
+ end
71
+
72
+ def validate_reply(reply)
73
+ reply
74
+ end
75
+ end
76
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ # Mp3repo::Application.routes.draw do
2
+ Rails.application.routes.draw do |map|
3
+ # resources :accounts, :controller => 'authr/accounts', :only => [:new, :create]
4
+ match 'webcli/cmd/:command', :controller => 'webcli/commands', :action => 'run'
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'rails/generators'
2
+
3
+ module Webcli
4
+ module Generators
5
+ class Base < Rails::Generators::Base #:nodoc:
6
+ def self.source_root
7
+ @_webcli_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'webcli', generator_name, 'templates'))
8
+ end
9
+
10
+ def self.banner
11
+ "#{$0} webcli:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,13 @@
1
+ require 'generators/webcli'
2
+
3
+ module Webcli
4
+ module Generators
5
+ class CopyfilesGenerator < Base
6
+ desc "installs files used by webcli"
7
+ def create_files
8
+ copy_file '~/lib/ruby/rails/plugins/webcli/app/controllers/webcli/commands_controller.rb', 'app/controllers/commands_controller.rb'
9
+ end
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,7 @@
1
+ Description:
2
+ The webcli:install generator installs all the requisite files required
3
+ for webcli to work in your rails applications.
4
+
5
+ Examples:
6
+ rails generate webcli:install
7
+ performs the installation
@@ -0,0 +1,18 @@
1
+ require 'generators/webcli'
2
+
3
+ module Webcli
4
+ module Generators
5
+ class InstallGenerator < Base
6
+ desc "installs files needed by webcli"
7
+ def create_files
8
+ copy_file 'webcli.js', "public/javascripts/plugin.jquery.webcli.js"
9
+ copy_file 'webcli.config.js', "public/javascripts/config.webcli.js"
10
+ copy_file 'webcli.css', "public/stylesheets/plugin.webcli.css"
11
+
12
+ say_status("fetching", "jQuery hotkeys plugin (google code 0.7.9)", :green)
13
+ get "http://js-hotkeys.googlecode.com/files/jquery.hotkeys-0.7.9.min.js", 'public/javascripts/jquery.hotkeys-0.7.9.min.js'
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ $(document).ready(function () {
2
+ RadCli.setup({
3
+ inputText: '',
4
+ prependText: '#',
5
+ rightTitle: '<strong>Title (edit javascripts/config.webcli.js to change)</strong>',
6
+ assetBase: 'http://127.0.0.1:3000' // No leading slash
7
+ });
8
+ $(document).bind('keyup', 'c', function() {
9
+ RadCli.focusPrompt()
10
+ });
11
+ });
@@ -0,0 +1,136 @@
1
+ /*--- The Cli ---*/
2
+ #cli-wrapper {
3
+ /* position:relative; */
4
+ }
5
+ #cli {
6
+ /* position: absolute;
7
+ left: 0;
8
+ z-index: 5000; */
9
+ width: 100%;
10
+ min-height: 36px;
11
+ display: block;
12
+ background: #000;
13
+ color: white;
14
+ font-family: Monaco, Courier, monospace;
15
+ font-size: 14px;
16
+
17
+ }
18
+ #cli-display {
19
+ background: #000;
20
+ padding: .5em 1em .5em 1em;
21
+ }
22
+ #cli-form {
23
+ background: none !important;
24
+ padding: 0 !important;
25
+ border: none;
26
+ margin: 0;
27
+ -moz-box-shadow: none;
28
+ -webkit-box-shadow: none;
29
+ box-shadow: none;
30
+ }
31
+ #cli-prepend {
32
+ background: #000;
33
+ height: 18px;
34
+ color: white;
35
+ padding:0 0 0 0.5em;
36
+ margin:0;
37
+ font-family: monospace;
38
+ font-size: 12px;
39
+ }
40
+
41
+ #cli-input {
42
+ width: 50em;
43
+ margin: 0 !important;
44
+ padding: 9px 0.4em;
45
+ /* background: url(../images/console-gt.gif) no-repeat left center; */
46
+ background: #000;
47
+ height: 18px;
48
+ border: 0;
49
+ color: white;
50
+ font-family: monospace;
51
+ font-size: 14px;
52
+ -moz-box-shadow: none;
53
+ -webkit-box-shadow: none;
54
+ box-shadow: none;
55
+ }
56
+ #cli input:focus {
57
+ outline: 0;
58
+ }
59
+ #cli-submit {
60
+ display: none;
61
+ }
62
+
63
+ #cli code, pre, .fixed {
64
+ font-family:Monaco,Courier,monospace;
65
+ font-size:12px;
66
+ font-weight:normal;
67
+ }
68
+ /*--- Git Shortcuts ---*/
69
+ #cli-title-right {
70
+ position: absolute;
71
+ top: 0;
72
+ right: 0;
73
+ z-index: 6000;
74
+ display: block;
75
+ height: 18px;
76
+ width: auto;
77
+ color: white;
78
+ font-size: 14px;
79
+ padding: 9px 1em;
80
+ }
81
+ #cli-title-right a {
82
+
83
+ margin: 0 4px;
84
+ /* height: 18px; */
85
+ border: 0;
86
+ font-family: Monaco, Courier, monospace;
87
+ /* font-size: 14px; */
88
+ font-weight: bold;
89
+ -moz-box-shadow: none;
90
+ -webkit-box-shadow: none;
91
+ box-shadow: none;
92
+
93
+ color:#00bbff;
94
+ text-decoration: none;
95
+ /* border-bottom:1px dashed #ff59ff; */
96
+ }
97
+ #cli-title-right a:hover {
98
+ color:black;
99
+ background:#00bbff;
100
+ /* border-bottom:1px solid #00bbff; */
101
+ }
102
+
103
+ /*
104
+ #cli-title-right .clone, #cli-title-right a {
105
+ margin: 0 4px;
106
+ /* height: 18px;
107
+ border: 0;
108
+ color: white;
109
+ font-family: monospace;
110
+ /* font-size: 14px;
111
+ -moz-box-shadow: none;
112
+ -webkit-box-shadow: none;
113
+ box-shadow: none;
114
+ }
115
+ #cli-title-right a {
116
+ width: 18px;
117
+ height: 0;
118
+ padding: 18px 0 0 0;
119
+ overflow: hidden;
120
+ border-bottom: none;
121
+ text-decoration: none;
122
+ color: #008dff;
123
+ }
124
+ #cli-title-right .download {
125
+ background: url(../img/icons/compressed.png) no-repeat center center;
126
+ }
127
+ #cli-title-right .copy {
128
+ z-index: 100;
129
+ background: url(../img/icons/clipboard.png) no-repeat center center;
130
+ }
131
+ #cli-title-right .help {
132
+ z-index:100;
133
+ background: url(../img/icons/help.png) no-repeat center center;
134
+ }
135
+ */
136
+
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Lithium: the most rad php framework
3
+ *
4
+ * @copyright Copyright 2009, Union of Rad (http://union-of-rad.org)
5
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
6
+ */
7
+
8
+ var RadCli = {
9
+ options: {
10
+ div: null,
11
+ },
12
+ html: {
13
+ cli: null,
14
+ git: null
15
+ },
16
+
17
+ /**
18
+ * Setup assigns options, creates the html and calls the appropriate css and javascript
19
+ *
20
+ * @var mixed options
21
+ * @return void
22
+ */
23
+ setup: function(setupOptions) {
24
+ if(setupOptions != null) {
25
+ $.extend(this.options, setupOptions);
26
+ }
27
+ this.loadGoods();
28
+ this.clearCli();
29
+
30
+ $('#cli-form').bind('submit', function() {
31
+ var command = $('#cli-input').val();
32
+ // alert(command);
33
+ if (command == "`") {
34
+ command = 'clear';
35
+ }
36
+ //RadCli.clearCli();
37
+ if (command != 'clear') {
38
+ prev_command = $('#cli-hidden').val();
39
+ $.getJSON(RadCli.options.assetBase + '/webcli/cmd/' + command, { input:command, prev_cmd:prev_command },RadCli.processJsonResponse);
40
+ }
41
+ if (command == 'clear') {
42
+ RadCli.resetCli();
43
+ $('#cli-input').focus();
44
+ $('#cli-input').select();
45
+ }
46
+ });
47
+ $('#container').click(function() {
48
+ RadCli.resetCli();
49
+ });
50
+ $("#cli").click(function() {
51
+ $('#cli-input').focus();
52
+ $('#cli-input').select();
53
+ });
54
+ // $("#cli-input").blur(function() {
55
+ // RadCli.resetCli();
56
+ // })
57
+ $("#cli").dblclick(function() {
58
+ $.getJSON(RadCli.options.assetBase + '/cmd/run_command.json', { cmd:'cli_process', text_input: 'help' },RadCli.processJsonResponse);
59
+ $('#cli-input').focus();
60
+ });
61
+ },
62
+
63
+ processJsonResponse: function(resp){
64
+ if (resp.status == 'SUCCESS') {
65
+ if (resp.type == 'TEXT') {
66
+ $('#cli-display').html(resp.text);
67
+ }
68
+ /*
69
+ if (resp.data.url) {
70
+ return window.location.href = resp.data.url;
71
+ } else {
72
+ $('#cli-display').html(resp.data.text);
73
+ }
74
+ */
75
+ RadCli.resetCli();
76
+ $('#cli-display').animate({
77
+ height: 'show',
78
+ opacity: 'show'
79
+ })
80
+
81
+ } else if (resp.status == 'NEED_MORE'){
82
+ RadCli.resetCli();
83
+ // alert('NEED MORE... text: ' + resp.data.text + ' ... prev_command: '+ resp.data.prev_cmd );
84
+ $('#cli-prepend').hide();
85
+ $('#cli-prepend').html(resp.data.text);
86
+ $('#cli-hidden').val(resp.data.prev_cmd);
87
+ $('#cli-prepend').fadeIn();
88
+
89
+ } else if (resp.status == "ERROR") {
90
+ RadCli.resetCli();
91
+ $('#cli-display').animate({
92
+ height: 'show',
93
+ opacity: 'show'
94
+ })
95
+ $('#cli-display').html('ERROR: ' + resp.text);
96
+ }
97
+ },
98
+
99
+ focusPrompt: function()
100
+ {
101
+ $('#cli-input').focus();
102
+ $('#cli-input').select();
103
+ },
104
+
105
+ loadGoods: function() {
106
+ var html = RadCli.createCliHtml() + RadCli.createTitleHtml();
107
+ html = $('<div id="cli-wrapper" />').hide().html(html);
108
+ $("body").prepend(html);
109
+ $("head").append(
110
+ '<link id="rad-cli-css" rel="stylesheet" type="text/css" href="' +
111
+ this.options.assetBase +
112
+ '/stylesheets/plugin.webcli.css" />'
113
+ );
114
+ $(window).load(function() {
115
+ $("#cli-wrapper").fadeIn();
116
+ $("#cli-input").val(RadCli.options.inputText).hide().delay(300).fadeIn()
117
+ $("#cli-prepend").hide().delay(300).fadeIn()
118
+
119
+ });
120
+ },
121
+
122
+ /**
123
+ * Generate, assign internally, and return string of html for Rad Cli bar
124
+ *
125
+ * @return string html
126
+ */
127
+ createCliHtml: function() {
128
+ var html = '';
129
+ html += '<div id="cli">';
130
+ html += '<div id="cli-display"></div>';
131
+ html += '<div>';
132
+ html += '<form id="cli-form" onSubmit="return false;">';
133
+ html += '<span id="cli-prepend">' + RadCli.options.prependText + '</span>'
134
+ html += '<input type="hidden" id="cli-hidden" value=""/>'
135
+ html += '<input id="cli-input" type="text" />';
136
+ html += '<input id="cli-submit" type="submit" />';
137
+ html += '</form>';
138
+ html += '</div>';
139
+ html += '</div>';
140
+ return this.html.cli = html;
141
+ },
142
+
143
+ /**
144
+ * Generate, assign internally, and return string of html for Rad Git path
145
+ *
146
+ * @return string html
147
+ */
148
+ createTitleHtml: function() {
149
+ var html = '';
150
+ if (this.options.rightTitle) {
151
+ html += '<div id="cli-title-right">';
152
+ html += '<span class="clone fixed">' + this.options.rightTitle + '</span>';
153
+ html += '</div>';
154
+ }
155
+ return this.html.git = html;
156
+ },
157
+
158
+ resetCli: function () {
159
+ $('#cli-display').hide();
160
+ $('#cli-hidden').val('');
161
+ $('#cli-prepend').html(this.options.prependText);
162
+ $('#cli-input').val(this.options.inputText);
163
+ $('#container').focus();
164
+
165
+ // $('#cli-display').hide();
166
+ // $('#cli-input').val('');
167
+ //$('#cli-input').focus();
168
+ },
169
+
170
+ clearCli: function () {
171
+ $('#cli-display').hide();
172
+ $('#cli-hidden').val('');
173
+ $('#cli-prepend').val(this.options.prependText);
174
+ $('#cli-input').val('');
175
+ $('#container').focus();
176
+ // $('#cli-display').hide();
177
+ // $('#cli-input').val('');
178
+ //$('#cli-input').focus();
179
+ }
180
+ }
181
+
data/lib/webcli.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Webcli
2
+ require 'webcli/engine' if defined?(Rails)
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'webcli'
2
+ require 'rails'
3
+
4
+ module Webcli
5
+ class Engine < Rails::Engine
6
+ # engine_name :webcli # supposedly deprecated (according to Warning)
7
+
8
+ rake_tasks do
9
+ load 'webcli/railties/tasks.rake'
10
+ end
11
+ end
12
+ end
File without changes
data/test/helper.rb ADDED
@@ -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 'webcli'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestWebcli < 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
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webcli
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Eduardo Del Balso
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-09 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ description: |-
34
+ This gem will add a black command line bar to the top of your webpage.
35
+ The code was initially inspired by and pulled (with permission) from the lithium php
36
+ framework's webpage; http://lithify.me/.
37
+ email: e.delbalso@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - LICENSE
44
+ - README.rdoc
45
+ files:
46
+ - app/controllers/webcli/commands_controller.rb
47
+ - config/routes.rb
48
+ - lib/generators/webcli.rb
49
+ - lib/generators/webcli/copyfiles/copyfiles_generator.rb
50
+ - lib/generators/webcli/install/USAGE
51
+ - lib/generators/webcli/install/install_generator.rb
52
+ - lib/generators/webcli/install/templates/webcli.config.js
53
+ - lib/generators/webcli/install/templates/webcli.css
54
+ - lib/generators/webcli/install/templates/webcli.js
55
+ - lib/webcli.rb
56
+ - lib/webcli/engine.rb
57
+ - lib/webcli/railties/tasks.rake
58
+ - LICENSE
59
+ - README.rdoc
60
+ - test/helper.rb
61
+ - test/test_webcli.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/edelbalso/webcli
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.3.7
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Adds a cli to your webapp
94
+ test_files:
95
+ - test/helper.rb
96
+ - test/test_webcli.rb