Permalink
Browse files

README, COPYING, cgi-methods, installation, and more.

  • Loading branch information...
1 parent a1e32a4 commit 03fc84f81d6f1d1580092ef2976495923842799d @rubys committed Dec 19, 2009
View
@@ -1 +1,2 @@
pkg
+doc
View
18 COPYING
@@ -0,0 +1,18 @@
+Copyright (c) 2009 Sam Ruby <rubys@intertwingly.net>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,6 +1,13 @@
+COPYING
Manifest
README
Rakefile
cgi-spa.gemspec
lib/cgi-spa.rb
-lib/version.rb
+lib/cgi-spa/builder.rb
+lib/cgi-spa/cgi-methods.rb
+lib/cgi-spa/environment.rb
+lib/cgi-spa/html-methods.rb
+lib/cgi-spa/installation.rb
+lib/cgi-spa/job-control.rb
+lib/cgi-spa/version.rb
View
66 README
@@ -1,23 +1,55 @@
-Provides the following globals:
- $cgi - Common Gateway Interface
- $params - Access to parameters
- $x - XmlBuilder instance
+= cgi-spa: Common Gateway Interface for Single Page Applications
- $USER - user
- $HOME - user's home directory
- $HOST - server host
+CGI-SPA provides a number of globals, helper methods, and monkey patches which
+simplify the development of single page applications in the form of CGI
+scripts.
- $HTTP_GET - request is an HTTP GET
- $HTTP_POST - request is an HTTP POST
- $XHR_JSON - request is XmlHttpRequest for JSON
+== Globals provided
+* $cgi - Common Gateway Interface
+* $param - Access to parameters (read-only OpenStruct like interface)
+* $x - XmlBuilder instance
+* $USER - Host user id
+* $HOME - Home directory
+* $SERVER- Server name
+* SELF - Request URI
+* SELF? - Request URI with '?' appended (avoids spoiling the cache)
-Helper methods:
- submit: runs command (or block) as a deamon process
+* $USER - user
+* $HOME - user's home directory
+* $HOST - server host
-MonkeyPatches to Builder:
- indented_text: matches text indentation to markup
- indented_data: useful for script and styles in HTML syntax
- traceback! : formats an exception traceback
+* $HTTP_GET - request is an HTTP GET
+* $HTTP_POST - request is an HTTP POST
+* $XHR_JSON - request is XmlHttpRequest for JSON
+* $XHTML - user agent accepts XHTML responses
- method_missing: patched to ensure open tags are closed
+== HTML methods
+* style! - argument is indented text/data
+* script! - argument is indented text/data
+== CGI methods
+* json - produce JSON output using the block specified
+* json! - produce JSON output using the block specified and exit
+* html - produce HTML output using the block specified
+* html! - produce HTML output using the block specified and exit
+* post - execute block only if method is POST
+* post! - if POST, produce HTML output using the block specified and exit
+
+== Helper methods
+* submit: runs command (or block) as a deamon process
+
+== Builder extensions
+* indented_text: matches text indentation to markup
+* indented_data: useful for script and styles in HTML syntax
+* traceback!: formats an exception traceback
+* method_missing: patched to ensure open tags are closed
+
+== Command line options
+When run from the command line, CGI name=value pairs can be specified.
+Additionally, the following options are supported:
+* --html: HTML (HTTP GET) output is expected
+* --post: HTML (HTTP POST) output is expected
+* --json: JSON (XML HTTP Request) output is expected
+* --xhtml: XHTML output is expected
+* --prompt: prompt for key/value pairs using stdin
+* --install=path: produce an suexec-callable wrapper script
View
@@ -2,7 +2,7 @@ require 'rubygems'
require 'rake'
require 'echoe'
-require File.expand_path(File.dirname(__FILE__) + "/lib/version")
+require File.expand_path(File.dirname(__FILE__) + "/lib/cgi-spa/version")
Echoe.new('cgi-spa', CgiSpa::VERSION::STRING) do |p|
p.summary = "CGI Single Page Applications"
View
@@ -2,18 +2,18 @@
Gem::Specification.new do |s|
s.name = %q{cgi-spa}
- s.version = "0.2.1"
+ s.version = "0.3.0"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Sam Ruby"]
- s.date = %q{2009-12-18}
+ s.date = %q{2009-12-19}
s.description = %q{ Provides a number of globals, helper methods, and monkey patches which
simplify the development of single page applications in the form of
CGI scripts.
}
s.email = %q{rubys@intertwingly.net}
- s.extra_rdoc_files = ["README", "lib/cgi-spa.rb", "lib/version.rb"]
- s.files = ["Manifest", "README", "Rakefile", "cgi-spa.gemspec", "lib/cgi-spa.rb", "lib/version.rb"]
+ s.extra_rdoc_files = ["COPYING", "README", "lib/cgi-spa.rb", "lib/cgi-spa/builder.rb", "lib/cgi-spa/cgi-methods.rb", "lib/cgi-spa/environment.rb", "lib/cgi-spa/html-methods.rb", "lib/cgi-spa/installation.rb", "lib/cgi-spa/job-control.rb", "lib/cgi-spa/version.rb"]
+ s.files = ["COPYING", "Manifest", "README", "Rakefile", "cgi-spa.gemspec", "lib/cgi-spa.rb", "lib/cgi-spa/builder.rb", "lib/cgi-spa/cgi-methods.rb", "lib/cgi-spa/environment.rb", "lib/cgi-spa/html-methods.rb", "lib/cgi-spa/installation.rb", "lib/cgi-spa/job-control.rb", "lib/cgi-spa/version.rb"]
s.homepage = %q{http://github.com/rubys/cgi-spa}
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cgi-spa", "--main", "README"]
s.require_paths = ["lib"]
View
@@ -1,169 +1,11 @@
-#!/usr/bin/ruby
require 'cgi'
-require 'rubygems'
require 'builder'
require 'json'
-# standard objects
-$cgi = CGI.new
-$param = $cgi.params
-$x = Builder::XmlMarkup.new :indent => 2
+require 'cgi-spa/environment'
+require 'cgi-spa/cgi-methods'
+require 'cgi-spa/html-methods'
+require 'cgi-spa/job-control'
+require 'cgi-spa/installation'
+require 'cgi-spa/builder'
-# get arguments if CGI couldn't find any...
-$param.merge!(CGI.parse(ARGV.join('&'))) if $param.empty?
-
-# fast path for accessing CGI parameters
-def $param.method_missing(name)
- self[name.to_s].join if has_key? name.to_s
-end
-
-# quick access to request_uri
-SELF = ENV['REQUEST_URI'].to_s
-def SELF?
- SELF + "?" # avoids spoiling the cache
-end
-
-# environment objects
-$USER = ENV['USER'] ||
- if RUBY_PLATFORM =~ /darwin/
- `dscl . -search /Users UniqueID #{Process.uid}`.split.first
- else
- `getent passwd #{Process.uid}`.split(':').first
- end
-
-$HOME = ENV['HOME'] || File.expand_path('~' + $USER)
-$SERVER = ENV['HTTP_HOST'] || `hostname`.chomp
-
-# request types
-$HTTP_GET = ($cgi.request_method == 'GET')
-$HTTP_POST = ($cgi.request_method == 'POST')
-$XHR_JSON = (ENV['HTTP_ACCEPT'] =~ /json/)
-
-# run command/block as a background daemon
-def submit(cmd=nil)
- fork do
- # detach from tty
- Process.setsid
- fork and exit
-
- # clear working directory and mask
- Dir.chdir '/'
- File.umask 0000
-
- # close open files
- STDIN.reopen '/dev/null'
- STDOUT.reopen '/dev/null', 'a'
- STDERR.reopen STDOUT
-
- # setup environment
- ENV['USER'] ||= $USER
- ENV['HOME'] ||= $HOME
-
- # run cmd and/or block
- system cmd if cmd
- yield if block_given?
- end
-end
-
-# add indented_text!, indented_data! and traceback! methods to builder
-module Builder
- class XmlMarkup
- unless method_defined? :indented_text!
- def indented_text!(text)
- indented_data!(text) {|data| text! data}
- end
- end
-
- unless method_defined? :indented_data!
- def indented_data!(data)
- return if data.strip.length == 0
- lines = data.gsub(/\n\s*\n/,"\n")
- unindent = lines.scan(/^ */).map {|str| str.length}.min
-
- before = Regexp.new('^'.ljust(unindent+1))
- after = " " * (@level * @indent)
- data = data.gsub(before, after)
-
- if block_given?
- yield data
- else
- self << data
- end
-
- _newline unless data =~ /\s$/
- end
- end
-
- unless method_defined? :traceback!
- def traceback!(exception=$!, klass='traceback')
- pre :class=>klass do
- text! exception.inspect
- _newline
- exception.backtrace.each {|frame| text!((' '*@indent)+frame + "\n")}
- end
- end
- end
- end
-end
-
-# monkey patch to ensure that tags are closed
-test =
- Builder::XmlMarkup.new.html do |x|
- x.body do
- begin
- x.p do
- raise Exception.new('boom')
- end
- rescue Exception => e
- x.pre e
- end
- end
- end
-
-if test.index('<p>') and !test.index('</p>')
- module Builder
- class XmlMarkup
- def method_missing(sym, *args, &block)
- text = nil
- attrs = nil
- sym = "#{sym}:#{args.shift}" if args.first.kind_of?(Symbol)
- args.each do |arg|
- case arg
- when Hash
- attrs ||= {}
- attrs.merge!(arg)
- else
- text ||= ''
- text << arg.to_s
- end
- end
- if block
- unless text.nil?
- raise ArgumentError, "XmlMarkup cannot mix a text argument with a block"
- end
- _indent
- _start_tag(sym, attrs)
- _newline
- begin ### Added
- _nested_structures(block)
- ensure ### Added
- _indent
- _end_tag(sym)
- _newline
- end ### Added
- elsif text.nil?
- _indent
- _start_tag(sym, attrs, true)
- _newline
- else
- _indent
- _start_tag(sym, attrs)
- text! text
- _end_tag(sym)
- _newline
- end
- @target
- end
- end
- end
-end
Oops, something went wrong.

0 comments on commit 03fc84f

Please sign in to comment.