wunderbar 0.8.6 → 0.8.7

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/Manifest CHANGED
@@ -1,6 +1,8 @@
1
1
  COPYING
2
- README
2
+ README.md
3
3
  Rakefile
4
+ demo/envdump.rb
5
+ demo/helloworld.rb
4
6
  demo/wiki.html
5
7
  demo/wiki.rb
6
8
  lib/wunderbar.rb
@@ -16,4 +18,5 @@ test/test_builder.rb
16
18
  test/test_html_markup.rb
17
19
  test/test_logger.rb
18
20
  tools/web2script.rb
21
+ wunderbar.gemspec
19
22
  Manifest
data/README.md ADDED
@@ -0,0 +1,212 @@
1
+ Wunderbar: Easy HTML5 applications
2
+ ===
3
+
4
+ Wunderbar makes it easy to produce valid HTML5, wellformed XHTML, Unicode
5
+ (utf-8), consistently indented, readable applications. This includes output
6
+ that conforms to the
7
+ [Polyglot](http://dev.w3.org/html5/html-xhtml-author-guide/) specification and
8
+ the emerging results from the [XML Error Recovery Community
9
+ Group](http://www.w3.org/community/xml-er/wiki/Main_Page).
10
+
11
+ Wunderbar is both inspired by, and builds upon Jim Weirich's
12
+ [Builder](https://github.com/jimweirich/builder#readme).
13
+
14
+ Quick Start
15
+ ---
16
+
17
+ Simple element:
18
+
19
+ _br
20
+
21
+ Nested elements:
22
+
23
+ _div do
24
+ _hr
25
+ end
26
+
27
+ Element with text:
28
+
29
+ _h1 "My weblog"
30
+
31
+ Element with attributes:
32
+
33
+ _img src: '/img/logo.jpg', alt: 'site logo'
34
+
35
+ Element with both text and attributes:
36
+
37
+ _a 'search', href: 'http://google.com'
38
+
39
+ Text:
40
+
41
+ _ "hello"
42
+
43
+ Mixed content (autospaced):
44
+
45
+ _p do
46
+ _ 'It is a'
47
+ _em 'very'
48
+ _ 'nice day.'
49
+ end
50
+
51
+ Mixed content (space controlled):
52
+
53
+ _p! do
54
+ _ 'Source is on '
55
+ _a 'github', href: 'https://github.com/'
56
+ _ '.'
57
+ end
58
+
59
+ Insert blank lines between rows in the HTML produced:
60
+
61
+ _tbody do
62
+ _tr_ do
63
+ _td 1
64
+ end
65
+ _tr_ do
66
+ _td 2
67
+ end
68
+ _tr_ do
69
+ _td 3
70
+ end
71
+ end
72
+
73
+ Capture exceptions:
74
+
75
+ _body? do
76
+ raise NotImplementedError.new('page')
77
+ end
78
+
79
+
80
+ Basic interface
81
+ ---
82
+
83
+ A typical main program produces one or more of HTML, JSON, or plain text
84
+ output. This is accomplished by providing one or more of the following:
85
+
86
+ Wunderbar.html do
87
+ code
88
+ end
89
+
90
+ Wunderbar.json do
91
+ expression
92
+ end
93
+
94
+ Wunderbar.text do
95
+ code
96
+ end
97
+
98
+ Arbitrary Ruby code can be placed in each. For html, use the `_` methods described here. For json, the results (typically a hash or array) are converted to JSON. For text, use `puts` and `print` statements to produce the desired results.
99
+
100
+ Methods provided to Wunderbar.html
101
+ ---
102
+
103
+ Invoking methods that start with a Unicode "low line" character ("_") will
104
+ generate a HTML tag. As with builder on which this library is based, these
105
+ tags can have text content and attributes. Tags can also be nested. Logic
106
+ can be freely intermixed.
107
+
108
+ Wunderbar knows which HTML tags need to be explicitly closed with separate end
109
+ tags (example: textarea), and which should never be closed with separate end
110
+ tags (example: br). It also takes care of HTML quoting and escaping of
111
+ arguments and text.
112
+
113
+ Suffixes after the tag name will modify the processing.
114
+
115
+ * `!`: turns off all special processing, including indenting
116
+ * `?`: adds code to rescue exceptions and produce tracebacks
117
+ * `_`: adds extra blank lines between this tag and siblings
118
+
119
+ The "`_`" method serves a number of purposes. Calling it with a single argument
120
+ produces text nodes. Inserting markup verbatim is done by "`_ << text`". A
121
+ number of other convenience methods are defined:
122
+
123
+ * _.`post?` -- was this invoked via HTTP POST?
124
+ * _.`system` -- invokes a shell command, captures stdin, stdout, and stderr
125
+ * _.`submit`: runs command (or block) as a deamon process
126
+
127
+ Access to all of the builder _defined_ methods (typically these end in an esclamation mark) and all of the Wunderbar module methods can be accessed in this way. Examples:
128
+
129
+ * `_.tag! :foo`
130
+ * `_.error 'Log message'`
131
+
132
+ Globals provided
133
+ ---
134
+ * `$cgi` - Common Gateway Interface
135
+ * `$param` - Access to parameters (read-only OpenStruct like interface)
136
+ * `$env` - Access to environment variables (read-only OpenStruct like interface)
137
+ * `$USER` - Host user id
138
+ * `$HOME` - Home directory
139
+ * `$SERVER`- Server name
140
+ * `SELF` - Request URI
141
+ * `SELF?` - Request URI with '?' appended (avoids spoiling the cache)
142
+ * `$HOME` - user's home directory
143
+ * `$HOST` - server host
144
+ * `$HTTP_GET` - request is an HTTP GET
145
+ * `$HTTP_POST` - request is an HTTP POST
146
+ * `$XHR_JSON` - request is XmlHttpRequest for JSON
147
+ * `$XHTML` - user agent accepts XHTML responses
148
+ * `$TEXT` - user agent accepts plain text responses
149
+
150
+ Also, the following environment variables are set if they aren't already:
151
+
152
+ * `HOME`
153
+ * `HTTP_HOST`
154
+ * `LANG`
155
+ * `REMOTE_USER`
156
+
157
+ Finally, the (Ruby 1.9.x) default external and internal encodings are set to
158
+ UTF-8. For Ruby 1.8, `$KCODE` is set to `U`
159
+
160
+ HTML methods
161
+ ---
162
+ * `_head`: insert meta charset utf-8
163
+ * `_svg`: insert svg namespace
164
+ * `_math`: insert math namespace
165
+ * `_coffeescript`: convert [coffeescript](http://coffeescript.org/) to JS and insert script tag
166
+
167
+ Note that adding an exclamation mark to the end of the tag name disables this
168
+ behavior.
169
+
170
+ CGI methods (deprecated?)
171
+ ---
172
+ * `json` - produce JSON output using the block specified
173
+ * `json!` - produce JSON output using the block specified and exit
174
+ * `html` - produce HTML output using the block specified
175
+ * `html!` - produce HTML output using the block specified and exit
176
+ * `post` - execute block only if method is POST
177
+ * `post!` - if POST, produce HTML output using the block specified and exit
178
+
179
+ OpenStruct methods (for $params and $env)
180
+ ---
181
+ * `untaint_if_match`: untaints value if it matches a regular expression
182
+
183
+ Builder extensions
184
+ ---
185
+ * `indented_text!`: matches text indentation to markup
186
+ * `indented_data!`: useful for script and styles in HTML syntax
187
+ * `disable_indendation!`: temporarily disable insertion of whitespace
188
+ * `margin!`: insert blank lines between tags
189
+
190
+ Logging:
191
+ ---
192
+ * _.`debug`: debug messages
193
+ * _.`info`: informational messages
194
+ * _.`warn`: warning messages
195
+ * _.`error`: error messages
196
+ * _.`fatal`: fatal error messages
197
+ * _.`log_level`=: set logging level (default: `:warn`)
198
+ * _.`logger`: return [Logger](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html) instance
199
+
200
+ Command line options
201
+ ---
202
+ When run from the command line, CGI name=value pairs can be specified.
203
+ Additionally, the following options are supported:
204
+
205
+ * --`html`: HTML (HTTP GET) output is expected
206
+ * --`post`: HTML (HTTP POST) output is expected
207
+ * --`json`: JSON (XML HTTP Request) output is expected
208
+ * --`xhtml`: XHTML output is expected
209
+ * --`prompt` or --`offline`: prompt for key/value pairs using stdin
210
+ * --`debug`, --`info`,--`warn`, --`error`, --`fatal`: set log level
211
+ * --`install`=path: produce an suexec-callable wrapper script
212
+ * --`rescue` or --`backtrace` cause wrapper script to capture errors
data/demo/envdump.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'wunderbar'
2
+
3
+ Wunderbar.html do
4
+ _head_ do
5
+ _title 'CGI Environment'
6
+ end
7
+ _body? do
8
+ _h1 'Environment Variables'
9
+ _table do
10
+ _tbody do
11
+ ENV.sort.each do |name, value|
12
+ _tr_ do
13
+ _td name
14
+ _td value
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ require 'wunderbar'
2
+
3
+ Wunderbar.html do
4
+ _head_ do
5
+ _title 'Greeter'
6
+ _style %{
7
+ input {display: block; margin: 2em}
8
+ }
9
+ end
10
+
11
+ _body? do
12
+ if @name
13
+ _p "Hello #{@name}!"
14
+ else
15
+ _form method: 'post' do
16
+ _p 'Please enter your name:'
17
+ _input name: 'name'
18
+ _input type: 'submit'
19
+ end
20
+ end
21
+ end
22
+ end
@@ -43,7 +43,7 @@ module Wunderbar
43
43
  @indent, @level = indent, level
44
44
  end
45
45
 
46
- def _margin
46
+ def margin!
47
47
  _newline unless @first_tag
48
48
  @pending_newline = false
49
49
  @pending_margin = true
@@ -85,7 +85,7 @@ end
85
85
  # produce html/xhtml
86
86
  def $cgi.html(*args, &block)
87
87
  return if $XHR_JSON or $TEXT
88
- args.push {} if args.empty?
88
+ args << {} if args.empty?
89
89
  args.first[:xmlns] ||= 'http://www.w3.org/1999/xhtml' if Hash === args.first
90
90
  mimetype = ($XHTML ? 'application/xhtml+xml' : 'text/html')
91
91
  x = HtmlMarkup.new
@@ -28,7 +28,7 @@ class HtmlMarkup
28
28
  end
29
29
 
30
30
  if name.sub!(/_$/,'')
31
- @x._margin
31
+ @x.margin!
32
32
  end
33
33
 
34
34
  if flag != '!'
@@ -1,30 +1,32 @@
1
1
  # run command/block as a background daemon
2
- def submit(cmd=nil)
3
- fork do
4
- # detach from tty
5
- Process.setsid
6
- fork and exit
2
+ module Wunderbar
3
+ def submit(cmd=nil)
4
+ fork do
5
+ # detach from tty
6
+ Process.setsid
7
+ fork and exit
7
8
 
8
- # clear working directory and mask
9
- Dir.chdir '/'
10
- File.umask 0000
9
+ # clear working directory and mask
10
+ Dir.chdir '/'
11
+ File.umask 0000
11
12
 
12
- # close open files
13
- STDIN.reopen '/dev/null'
14
- STDOUT.reopen '/dev/null', 'a'
15
- STDERR.reopen STDOUT
13
+ # close open files
14
+ STDIN.reopen '/dev/null'
15
+ STDOUT.reopen '/dev/null', 'a'
16
+ STDERR.reopen STDOUT
16
17
 
17
- # clear environment of cgi cruft
18
- ENV.keys.to_a.each do |key|
19
- ENV.delete(key) if key =~ /HTTP/ or $cgi.respond_to? key.downcase
20
- end
18
+ # clear environment of cgi cruft
19
+ ENV.keys.to_a.each do |key|
20
+ ENV.delete(key) if key =~ /HTTP/ or $cgi.respond_to? key.downcase
21
+ end
21
22
 
22
- # setup environment
23
- ENV['USER'] ||= $USER
24
- ENV['HOME'] ||= $HOME
23
+ # setup environment
24
+ ENV['USER'] ||= $USER
25
+ ENV['HOME'] ||= $HOME
25
26
 
26
- # run cmd and/or block
27
- system cmd if cmd
28
- yield if block_given?
27
+ # run cmd and/or block
28
+ system cmd if cmd
29
+ yield if block_given?
30
+ end
29
31
  end
30
32
  end
@@ -2,7 +2,7 @@ module Wunderbar
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 8
5
- TINY = 6
5
+ TINY = 7
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/wunderbar.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "wunderbar"
5
- s.version = "0.8.6"
5
+ s.version = "0.8.7"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sam Ruby"]
9
9
  s.date = "2012-03-17"
10
10
  s.description = " Provides a number of globals, helper methods, and monkey patches which\n simplify the generation of HTML and the development of CGI scripts.\n"
11
11
  s.email = "rubys@intertwingly.net"
12
- s.extra_rdoc_files = ["COPYING", "README", "lib/wunderbar.rb", "lib/wunderbar/builder.rb", "lib/wunderbar/cgi-methods.rb", "lib/wunderbar/environment.rb", "lib/wunderbar/html-methods.rb", "lib/wunderbar/installation.rb", "lib/wunderbar/job-control.rb", "lib/wunderbar/logger.rb", "lib/wunderbar/version.rb"]
13
- s.files = ["COPYING", "README", "Rakefile", "demo/wiki.html", "demo/wiki.rb", "lib/wunderbar.rb", "lib/wunderbar/builder.rb", "lib/wunderbar/cgi-methods.rb", "lib/wunderbar/environment.rb", "lib/wunderbar/html-methods.rb", "lib/wunderbar/installation.rb", "lib/wunderbar/job-control.rb", "lib/wunderbar/logger.rb", "lib/wunderbar/version.rb", "test/test_builder.rb", "test/test_html_markup.rb", "test/test_logger.rb", "tools/web2script.rb", "Manifest", "wunderbar.gemspec"]
12
+ s.extra_rdoc_files = ["COPYING", "README.md", "lib/wunderbar.rb", "lib/wunderbar/builder.rb", "lib/wunderbar/cgi-methods.rb", "lib/wunderbar/environment.rb", "lib/wunderbar/html-methods.rb", "lib/wunderbar/installation.rb", "lib/wunderbar/job-control.rb", "lib/wunderbar/logger.rb", "lib/wunderbar/version.rb"]
13
+ s.files = ["COPYING", "README.md", "Rakefile", "demo/envdump.rb", "demo/helloworld.rb", "demo/wiki.html", "demo/wiki.rb", "lib/wunderbar.rb", "lib/wunderbar/builder.rb", "lib/wunderbar/cgi-methods.rb", "lib/wunderbar/environment.rb", "lib/wunderbar/html-methods.rb", "lib/wunderbar/installation.rb", "lib/wunderbar/job-control.rb", "lib/wunderbar/logger.rb", "lib/wunderbar/version.rb", "test/test_builder.rb", "test/test_html_markup.rb", "test/test_logger.rb", "tools/web2script.rb", "wunderbar.gemspec", "Manifest"]
14
14
  s.homepage = "http://github.com/rubys/wunderbar"
15
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Wunderbar", "--main", "README"]
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Wunderbar", "--main", "README.md"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = "wunderbar"
18
18
  s.rubygems_version = "1.8.15"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wunderbar
3
3
  version: !ruby/object:Gem::Version
4
- hash: 51
4
+ hash: 49
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 6
10
- version: 0.8.6
9
+ - 7
10
+ version: 0.8.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Ruby
@@ -53,7 +53,7 @@ extensions: []
53
53
 
54
54
  extra_rdoc_files:
55
55
  - COPYING
56
- - README
56
+ - README.md
57
57
  - lib/wunderbar.rb
58
58
  - lib/wunderbar/builder.rb
59
59
  - lib/wunderbar/cgi-methods.rb
@@ -65,8 +65,10 @@ extra_rdoc_files:
65
65
  - lib/wunderbar/version.rb
66
66
  files:
67
67
  - COPYING
68
- - README
68
+ - README.md
69
69
  - Rakefile
70
+ - demo/envdump.rb
71
+ - demo/helloworld.rb
70
72
  - demo/wiki.html
71
73
  - demo/wiki.rb
72
74
  - lib/wunderbar.rb
@@ -82,8 +84,8 @@ files:
82
84
  - test/test_html_markup.rb
83
85
  - test/test_logger.rb
84
86
  - tools/web2script.rb
85
- - Manifest
86
87
  - wunderbar.gemspec
88
+ - Manifest
87
89
  homepage: http://github.com/rubys/wunderbar
88
90
  licenses: []
89
91
 
@@ -94,7 +96,7 @@ rdoc_options:
94
96
  - --title
95
97
  - Wunderbar
96
98
  - --main
97
- - README
99
+ - README.md
98
100
  require_paths:
99
101
  - lib
100
102
  required_ruby_version: !ruby/object:Gem::Requirement
data/README DELETED
@@ -1,99 +0,0 @@
1
- = Wunderbar: Common Gateway Interface for Single Page Applications
2
-
3
- Wunder provides a number of globals, helper methods, and monkey patches which
4
- simplify the development of single page applications in the form of CGI
5
- scripts.
6
-
7
- Basic interface
8
- ===============
9
-
10
- A typical main program produces one or more of HTML, JSON, or plain text
11
- output. This is accomplished by providing one or more of the following:
12
-
13
- Wunderbar.html do
14
- code
15
- end
16
-
17
- Wunderbar.json do
18
- expression
19
- end
20
-
21
- Wunderbar.text do
22
- code
23
- end
24
-
25
- Arbitrary Ruby code can be placed in each.
26
-
27
- == Methods provided to Wunderbar.html
28
-
29
- Invoking methods that start with a Unicode "low line" character ("_") will
30
- generate a HTML tag. As with builder on which this library is based, these
31
- tags can have text content and attributes. Tags can also be nested. Logic
32
- can be freely intermixed.
33
-
34
- Wunderbar knows which HTML tags need to be explicitly closed with separate end
35
- tags (example: textarea), and which should never be closed with separate end
36
- tags (example: br). It also takes care of HTML quoting and escaping of
37
- arguments and text.
38
-
39
- The "_" method serves a number of purposes. Calling it with a single argument
40
- produces text nodes. Inserting markup verbatim is done by "_ << text". A
41
- number of other convenience methods are defined:
42
-
43
- _.post? -- was this invoked via HTTP POST?
44
- _.system -- invokes a shell command, captures stdin, stdout, and stderr
45
-
46
- == Globals provided
47
- * $cgi - Common Gateway Interface
48
- * $param - Access to parameters (read-only OpenStruct like interface)
49
- * $env - Access to environment variables (read-only OpenStruct like interface)
50
- * $USER - Host user id
51
- * $HOME - Home directory
52
- * $SERVER- Server name
53
- * SELF - Request URI
54
- * SELF? - Request URI with '?' appended (avoids spoiling the cache)
55
-
56
- * $USER - user
57
- * $HOME - user's home directory
58
- * $HOST - server host
59
-
60
- * $HTTP_GET - request is an HTTP GET
61
- * $HTTP_POST - request is an HTTP POST
62
- * $XHR_JSON - request is XmlHttpRequest for JSON
63
- * $XHTML - user agent accepts XHTML responses
64
-
65
- == HTML methods
66
- * style! - argument is indented text/data
67
- * system! - run command and capture output
68
- * script! - argument is indented text/data
69
- * body? - capture exceptions, and produce a stack traceback
70
-
71
- == CGI methods
72
- * json - produce JSON output using the block specified
73
- * json! - produce JSON output using the block specified and exit
74
- * html - produce HTML output using the block specified
75
- * html! - produce HTML output using the block specified and exit
76
- * post - execute block only if method is POST
77
- * post! - if POST, produce HTML output using the block specified and exit
78
-
79
- == Helper methods
80
- * submit: runs command (or block) as a deamon process
81
-
82
- == OpenStruct methods (for $params and $env)
83
- * untaint_if_match: untaints value if it matches a regular expression
84
-
85
- == Builder extensions
86
- * indented_text: matches text indentation to markup
87
- * indented_data: useful for script and styles in HTML syntax
88
- * traceback!: formats an exception traceback
89
- * method_missing: patched to ensure open tags are closed
90
-
91
- == Command line options
92
- When run from the command line, CGI name=value pairs can be specified.
93
- Additionally, the following options are supported:
94
- * --html: HTML (HTTP GET) output is expected
95
- * --post: HTML (HTTP POST) output is expected
96
- * --json: JSON (XML HTTP Request) output is expected
97
- * --xhtml: XHTML output is expected
98
- * --prompt: prompt for key/value pairs using stdin
99
- * --install=path: produce an suexec-callable wrapper script