tarpaulin 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +25 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bivouac.gemspec +71 -0
- data/lib/tarpaulin.rb +109 -0
- data/lib/tarpaulin/camping.rb +91 -0
- data/lib/tarpaulin/endless.rb +50 -0
- data/lib/tarpaulin/logger.rb +49 -0
- data/lib/tarpaulin/tilt/clearsilver_template.rb +87 -0
- data/tarpaulin.gemspec +72 -0
- data/test/helper.rb +18 -0
- data/test/test_kommons.rb +7 -0
- metadata +191 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# http://twiddlewakka.com/
|
7
|
+
# http://robots.thoughtbot.com/post/2508037841/twiddle-wakka
|
8
|
+
# http://robots.thoughtbot.com/post/2729333530/fetching-source-index-for-http-rubygems-org
|
9
|
+
|
10
|
+
# ~> x.y.z is between >= x.y.z an < x.y+1.0
|
11
|
+
# ~> x.y is between >= x.y < x+1
|
12
|
+
|
13
|
+
gem 'tilt', '~> 1.3.1' # https://github.com/rtomayko/tilt
|
14
|
+
gem 'lazy', '~> 0.9.6' # http://moonbase.rydia.net/software/lazy.rb/
|
15
|
+
# gem 'erubis', '~> 2.7.0' # http://www.kuwata-lab.com/erubis/
|
16
|
+
|
17
|
+
# Add dependencies to develop your gem here.
|
18
|
+
# Include everything needed to run rake, tests, features, etc.
|
19
|
+
group :development do
|
20
|
+
gem "shoulda", "~> 2.11.1" # https://github.com/thoughtbot/shoulda
|
21
|
+
gem "bundler", "~> 1.0.0" # http://gembundler.com/
|
22
|
+
gem "jeweler", "~> 1.6.1" # https://github.com/technicalpickles/jeweler
|
23
|
+
gem "rcov", "~> 0.9.7" # http://relevance.github.com/rcov
|
24
|
+
gem "rdoc", "~> 3.9.1" # http://rdoc.rubyforge.org/
|
25
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Anthony Durity
|
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,19 @@
|
|
1
|
+
= kommons
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to kommons
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Anthony Durity. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "tarpaulin"
|
18
|
+
gem.homepage = "http://github.com/igravious/tarpaulin"
|
19
|
+
gem.license = "GPLv3"
|
20
|
+
gem.summary = %Q{Useful Camping and Web app helper methods}
|
21
|
+
gem.description = %Q{So I don't have to copy and paste a million times.}
|
22
|
+
gem.email = "github@jollyrotten.org"
|
23
|
+
gem.authors = ["Anthony Durity"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rcov/rcovtask'
|
36
|
+
Rcov::RcovTask.new do |test|
|
37
|
+
test.libs << 'test'
|
38
|
+
test.pattern = 'test/**/test_*.rb'
|
39
|
+
test.verbose = true
|
40
|
+
test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
RDoc::Task.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "Tarpaulin #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/bivouac.gemspec
ADDED
@@ -0,0 +1,71 @@
|
|
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 = "bivouac"
|
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 = ["Anthony Durity"]
|
12
|
+
s.date = "2011-10-13"
|
13
|
+
s.description = "So I don't have to copy and paste a million times."
|
14
|
+
s.email = "github@jollyrotten.org"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"bivouac.gemspec",
|
27
|
+
"lib/bivouac.rb",
|
28
|
+
"lib/bivouac/camping.rb",
|
29
|
+
"lib/bivouac/endless.rb",
|
30
|
+
"lib/bivouac/logger.rb",
|
31
|
+
"lib/bivouac/tilt/clearsilver_template.rb",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_kommons.rb"
|
34
|
+
]
|
35
|
+
s.homepage = "http://github.com/igravious/bivouac"
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = "1.8.11"
|
39
|
+
s.summary = "Useful Camping and Web app helper methods"
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<tilt>, ["~> 1.3.1"])
|
46
|
+
s.add_runtime_dependency(%q<lazy>, ["~> 0.9.6"])
|
47
|
+
s.add_development_dependency(%q<shoulda>, ["~> 2.11.1"])
|
48
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.1"])
|
50
|
+
s.add_development_dependency(%q<rcov>, ["~> 0.9.7"])
|
51
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.9.1"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<tilt>, ["~> 1.3.1"])
|
54
|
+
s.add_dependency(%q<lazy>, ["~> 0.9.6"])
|
55
|
+
s.add_dependency(%q<shoulda>, ["~> 2.11.1"])
|
56
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.1"])
|
58
|
+
s.add_dependency(%q<rcov>, ["~> 0.9.7"])
|
59
|
+
s.add_dependency(%q<rdoc>, ["~> 3.9.1"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<tilt>, ["~> 1.3.1"])
|
63
|
+
s.add_dependency(%q<lazy>, ["~> 0.9.6"])
|
64
|
+
s.add_dependency(%q<shoulda>, ["~> 2.11.1"])
|
65
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.1"])
|
67
|
+
s.add_dependency(%q<rcov>, ["~> 0.9.7"])
|
68
|
+
s.add_dependency(%q<rdoc>, ["~> 3.9.1"])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
data/lib/tarpaulin.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# = About lib/tarpaulin.rb
|
2
|
+
#
|
3
|
+
# By requiring <tt>lib/tarpaulin</tt>, you can load Tarpaulin's dependencies
|
4
|
+
# (the lazy library,)
|
5
|
+
# (,)
|
6
|
+
# as well as the full set of Tarpaulin classes.
|
7
|
+
#
|
8
|
+
# For a full list of features and instructions, see the README.
|
9
|
+
|
10
|
+
|
11
|
+
# documenfuckingtation?
|
12
|
+
require 'rubygems'
|
13
|
+
require "bundler/setup"
|
14
|
+
|
15
|
+
# because this uses caller, let's place it in Kernel
|
16
|
+
# it's got a long name, nothing will conflict
|
17
|
+
# http://grosser.it/2009/07/01/getting-the-caller-method-in-ruby/
|
18
|
+
# this is like parse_caller() in ActionMailer apparently
|
19
|
+
module Kernel
|
20
|
+
|
21
|
+
# return [n, dirname, filename or context, line num, self, function]
|
22
|
+
def determine_context (skip=1, &block)
|
23
|
+
begin
|
24
|
+
# cheat, just in case it is nil, rather than handling that special case for now
|
25
|
+
# cuz it's always possible to call a func that takes a block without an actual block :(
|
26
|
+
# i suppose i could raise an ExpectingBlock Error
|
27
|
+
b = block.send(:binding)
|
28
|
+
snarf = caller(0)[skip] # defaults to 1
|
29
|
+
# [0] is us --- ["../y_ruby/c.rb:9:in `determine_context'",
|
30
|
+
#err "caller(): #{snarf.inspect}"
|
31
|
+
matched = /^(.+?)[:](\d+)(.*)$/.match(snarf) # +? non-greedy
|
32
|
+
#err "matched /^(.+?)[:](\d+)(.*)$/: #{matched}"
|
33
|
+
# the whole thing is matched[0]
|
34
|
+
context = matched[1] # is file or (eval) or (irb) or ...
|
35
|
+
line_no = matched[2].to_i
|
36
|
+
three = matched[3]
|
37
|
+
#err "context = matched[1]: #{context}"
|
38
|
+
#err "line_no = matched[2]: #{line_no}"
|
39
|
+
#err "three = matched[2]: #{three}"
|
40
|
+
#err "three is empty?: #{three.length.zero?.inspect}"
|
41
|
+
fn = nil
|
42
|
+
unless three.length.zero?
|
43
|
+
matched = /^:in `(.+?)'$/.match(three)
|
44
|
+
#err "matched /^:in `(.+?)'$/: #{matched}"
|
45
|
+
fn = matched[1]
|
46
|
+
#err "fn = matched[1]: #{fn}"
|
47
|
+
end
|
48
|
+
first_letter = context[0]
|
49
|
+
#err "first_letter = context[0]: #{first_letter}"
|
50
|
+
case first_letter
|
51
|
+
when 40 # _(_ we do not handle (irb) and (eval) and whatever else yet
|
52
|
+
{:type => 0, :path => Dir.getwd, :location => context, :line_number => line_no, :self => eval("self", b), :function => fn}
|
53
|
+
#return Dir.getwd + '/' + string
|
54
|
+
when 47 # _/_ absolute
|
55
|
+
{:type => 1, :path => File.dirname(context), :location => File.basename(context), :line_number => line_no, :self => eval("self", b), :function => fn}
|
56
|
+
#return File.dirname(context) + '/' + string
|
57
|
+
when 46 # _._ relative ... to what?! i suppose the working dir unless it was changed :( (need a per binding ENV?)
|
58
|
+
{:type => 2, :path => File.expand_path(File.dirname(context), ENV['PWD']), :location => File.basename(context), :line_number => line_no, :self => eval("self", b), :function => fn}
|
59
|
+
#return File.expand_path(File.dirname(context)) + '/' + string
|
60
|
+
else # bare file name i guess unless something weird is happening
|
61
|
+
{:type => 3, :path => File.expand_path(File.dirname(context), ENV['PWD']), :location => File.basename(context), :line_number => line_no, :self => eval("self", b), :function => fn}
|
62
|
+
#raise NameError.new("odd name found in backtrace -- " + context)
|
63
|
+
end # case
|
64
|
+
end # begin
|
65
|
+
end # determine_context()
|
66
|
+
|
67
|
+
end # module Kernel
|
68
|
+
|
69
|
+
# Recognizing that Dir.getwd is not always the dir of the file being interpreted
|
70
|
+
#
|
71
|
+
# Thus the pattern has been
|
72
|
+
# $:.unshift(File.dirname(__FILE__))
|
73
|
+
# which according to http://gilesbowkett.blogspot.com/2009/04/unshiftfiledirnamefile.html
|
74
|
+
# This shit is evil. People are undecided as to how evil, but evil it is.
|
75
|
+
#
|
76
|
+
# Preferable is
|
77
|
+
# require File.expand_path(File.dirname(__FILE__)) + "foo"
|
78
|
+
#
|
79
|
+
# but then you have a load of File.expand_path(File.dirname(__FILE__)) everywhere
|
80
|
+
# so it would be nice to have File.here , as in
|
81
|
+
# require File.here "foo"
|
82
|
+
class File
|
83
|
+
|
84
|
+
def File.here (string)
|
85
|
+
return determine_context(2){}[:path] + '/' + string
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
# Tarpaulin is a module containing all of the great Tarpaulin classes that
|
91
|
+
# do such an excellent job. These are snippets of code common to my Camping apps
|
92
|
+
#
|
93
|
+
# * custom class Logger
|
94
|
+
#
|
95
|
+
# * catch all class Endless
|
96
|
+
#
|
97
|
+
# * Tarpaulin main module and Helpers
|
98
|
+
#
|
99
|
+
# * Tilt template for ClearSilver
|
100
|
+
#
|
101
|
+
module Tarpaulin
|
102
|
+
version_file = File.expand_path(File.here "/../VERSION")
|
103
|
+
VERSION = File.read(version_file).strip
|
104
|
+
end
|
105
|
+
|
106
|
+
require File.here "tarpaulin/logger"
|
107
|
+
require File.here "tarpaulin/endless"
|
108
|
+
require File.here "tarpaulin/camping"
|
109
|
+
require File.here "tarpaulin/tilt/clearsilver_template"
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#
|
2
|
+
# included into top-level TheApp module
|
3
|
+
#
|
4
|
+
# overrides r404, defines r403
|
5
|
+
# tells Tarpaulin which Controller in TheApp handles static files
|
6
|
+
#
|
7
|
+
# don't need to require anything as these are modules that are
|
8
|
+
# included elsewhere and those elsewhere require stuff :)
|
9
|
+
module Tarpaulin
|
10
|
+
|
11
|
+
@@link = nil
|
12
|
+
def self.link_controller=(link)
|
13
|
+
@@link = link
|
14
|
+
end
|
15
|
+
def self.link_controller
|
16
|
+
@@link
|
17
|
+
end
|
18
|
+
|
19
|
+
def r403(&block)
|
20
|
+
#$stderr.puts "in 403"
|
21
|
+
h = {'Content-Type' => 'text/html; charset=utf-8'}
|
22
|
+
# a = eval("determine_context{}", block)
|
23
|
+
# html_msg = "<!DOCTYPE html><html lang='en'><head><title>« Uh oh »</title><body><span class='error'>Site error (BEEP!) 403: Invalid Path: #{block.call}<br>#{a.inspect}</span></body>"
|
24
|
+
html_msg = "<!DOCTYPE html><html lang='en'><head><title>« Uh oh »</title><body><span class='error'>Site error (BEEP!) 403: Invalid Path: #{block.call}<br></span></body>"
|
25
|
+
r(403, html_msg, h)
|
26
|
+
end
|
27
|
+
|
28
|
+
def r404(&block)
|
29
|
+
#$stderr.puts "in 404"
|
30
|
+
h = {'Content-Type' => 'text/html; charset=utf-8'}
|
31
|
+
# a = eval("determine_context{}", block)
|
32
|
+
# html_msg = "<!DOCTYPE html><html lang='en'><head><title>« Uh oh »</title><body><span class='error'>Site error (BEEP!) 404: File not found: #{block.call}<br>#{a.inspect}</span></body>"
|
33
|
+
html_msg = "<!DOCTYPE html><html lang='en'><head><title>« Uh oh »</title><body><span class='error'>Site error (BEEP!) 404: File not found: #{block.call}<br></span></body>"
|
34
|
+
r(404, html_msg, h)
|
35
|
+
end
|
36
|
+
|
37
|
+
# included into TheApp::Helpers module
|
38
|
+
|
39
|
+
module Helpers
|
40
|
+
|
41
|
+
# this is a dev file - should be in a config
|
42
|
+
def document_root # or whatever ...
|
43
|
+
# '/var/www/localhost/htdocs/'
|
44
|
+
# /Users/jollyrotten/Code/poetify/y_ruby
|
45
|
+
File.dirname(__FILE__)
|
46
|
+
end
|
47
|
+
|
48
|
+
def http_host # or whatever ...
|
49
|
+
# 'http://web.durity.com:8080/'
|
50
|
+
'http://localhost:3301/'
|
51
|
+
end
|
52
|
+
|
53
|
+
# could do all these with a bit of meta-programming
|
54
|
+
|
55
|
+
IMAGE = 'images'
|
56
|
+
def image_dir
|
57
|
+
File.join(document_root, IMAGE)
|
58
|
+
end
|
59
|
+
|
60
|
+
CSS = 'cascading_stylesheets' # cascading_stylesheets
|
61
|
+
def css_dir
|
62
|
+
File.join(document_root, CSS)
|
63
|
+
end
|
64
|
+
|
65
|
+
JS = 'javascripts'
|
66
|
+
def js_dir
|
67
|
+
File.join(document_root, JS)
|
68
|
+
end
|
69
|
+
|
70
|
+
def stylesheet_link_tag(stylish)
|
71
|
+
type = "text/css"
|
72
|
+
href = stylish.start_with?("http") ? "#{stylish}" : R(Tarpaulin.link_controller, Tarpaulin::Helpers::CSS, "#{stylish}.css")
|
73
|
+
Markaby::Builder.new.capture {
|
74
|
+
link :rel => "stylesheet",
|
75
|
+
:type => type,
|
76
|
+
:media => "screen",
|
77
|
+
:href => href
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
def javascript_link_tag(scriptish)
|
82
|
+
type = "text/javascript"
|
83
|
+
src = scriptish.start_with?("http") ? "#{scriptish}" : R(Tarpaulin.link_controller, Tarpaulin::Helpers::JS, "#{scriptish}.js")
|
84
|
+
Markaby::Builder.new.capture {
|
85
|
+
script(:type => type, :src => src) {}
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
end # module Helpers
|
90
|
+
|
91
|
+
end # module Tarpaulin
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
# doc (look up rdoc)
|
3
|
+
|
4
|
+
require 'lazy'
|
5
|
+
|
6
|
+
class Endless
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
make_a_promise Lazy.promise &Proc.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def make_a_promise(p)
|
14
|
+
@p = p
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_promise
|
18
|
+
@p
|
19
|
+
end
|
20
|
+
|
21
|
+
def each
|
22
|
+
p = get_promise
|
23
|
+
a = []
|
24
|
+
while p
|
25
|
+
car, cdr = p
|
26
|
+
head_by_tail = car[1]
|
27
|
+
a << head_by_tail
|
28
|
+
yield head_by_tail
|
29
|
+
p = cdr.get_promise
|
30
|
+
end
|
31
|
+
a
|
32
|
+
end
|
33
|
+
|
34
|
+
def map
|
35
|
+
p = get_promise
|
36
|
+
a = []
|
37
|
+
while p
|
38
|
+
car, cdr = p
|
39
|
+
head_by_tail = car[1]
|
40
|
+
a << (yield head_by_tail)
|
41
|
+
p = cdr.get_promise
|
42
|
+
end
|
43
|
+
a
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def endless_path(head, tail)
|
49
|
+
Endless.new { [[tail, head * tail], endless_path(head, tail+1)] }
|
50
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
class Logger
|
4
|
+
|
5
|
+
def self.format_block # implicit
|
6
|
+
the_proc = Proc.new # capture it
|
7
|
+
context = eval("determine_context{}", the_proc) # eval can take a Proc obj or a Binding
|
8
|
+
result = the_proc.call # invoke it
|
9
|
+
klass = 'nil' # can it be??
|
10
|
+
# puts context[:self].inspect
|
11
|
+
if context[:self]
|
12
|
+
klass = context[:self].class.to_s.split('::').last
|
13
|
+
if klass == "Object" : klass = 'main' end
|
14
|
+
end
|
15
|
+
if context[:function]
|
16
|
+
if klass
|
17
|
+
context = "#{context[:location]} #{klass}.#{context[:function]}()"
|
18
|
+
else
|
19
|
+
context = "#{context[:location]} #{context[:function]}()"
|
20
|
+
end
|
21
|
+
else
|
22
|
+
context = "#{context[:location]} #{klass}@#{context[:line_number]}"
|
23
|
+
end
|
24
|
+
case result
|
25
|
+
when String # maybe respond_to? is better but meh ...
|
26
|
+
return "[#{context}]: #{result}" # time stamp
|
27
|
+
else
|
28
|
+
return "[#{context}]: #{result.inspect}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
%w(debug info warn error fatal).each do |sev|
|
33
|
+
orig_method = ('orig_'+sev).to_sym
|
34
|
+
method = sev.to_sym
|
35
|
+
alias_method( orig_method, method)
|
36
|
+
class_eval <<-"END"
|
37
|
+
def #{method}
|
38
|
+
output = Logger.format_block(&Proc.new)
|
39
|
+
#{orig_method}(output)
|
40
|
+
end
|
41
|
+
END
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
$logger = Logger.new(STDOUT)
|
47
|
+
$logger.level = Logger::DEBUG
|
48
|
+
# DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
|
49
|
+
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
require 'tilt/template'
|
3
|
+
|
4
|
+
# prefer Erubis
|
5
|
+
# http://www.kuwata-lab.com/erubis/
|
6
|
+
# require 'erubis'
|
7
|
+
# Tilt.register :erb, Tilt[:erubis]
|
8
|
+
# Tilt.register :rhtml, Tilt[:erubis]
|
9
|
+
|
10
|
+
require 'neo'
|
11
|
+
|
12
|
+
module Tilt
|
13
|
+
# ClearSilver implementation. See:
|
14
|
+
# my https://github.com/igravious/clearsilver gist
|
15
|
+
class ClearSilverTemplate < Tilt::Template
|
16
|
+
|
17
|
+
def self.engine_initialized?
|
18
|
+
defined? ::ClearSilver
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize_engine
|
22
|
+
#require_template_library 'neo' # not thread-safe apparently
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
attr_accessor 'old_api'
|
27
|
+
def old_api? ; old_api end
|
28
|
+
# old_api = true <--- does not work !!!
|
29
|
+
end
|
30
|
+
|
31
|
+
ClearSilverTemplate.old_api = false
|
32
|
+
|
33
|
+
attr_accessor 'additive_parsing'
|
34
|
+
def additive_parsing? ; additive_parsing end
|
35
|
+
|
36
|
+
def debug # implicit
|
37
|
+
if $logger
|
38
|
+
#$logger.debug(&Proc.new) # pass it along
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def prepare
|
43
|
+
# data comes from tilt
|
44
|
+
debug { "#0" }
|
45
|
+
unless data.length.zero?
|
46
|
+
debug { "#1" }
|
47
|
+
@data = data
|
48
|
+
@engine = nil
|
49
|
+
@output = nil
|
50
|
+
@already_parsed = false
|
51
|
+
@additive_parsing = false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def evaluate(scope, locals, &block)
|
56
|
+
|
57
|
+
debug { scope }
|
58
|
+
debug { locals }
|
59
|
+
debug { block }
|
60
|
+
if block
|
61
|
+
hd = block.call
|
62
|
+
else
|
63
|
+
hd = scope
|
64
|
+
end
|
65
|
+
if ClearSilverTemplate.old_api
|
66
|
+
debug { "#2" }
|
67
|
+
@engine = Neo::Cs.new hd unless @engine # CS Ruby API, traditional
|
68
|
+
if !@already_parsed or additive_parsing?
|
69
|
+
debug { "#2.5" }
|
70
|
+
# boooooh, can't be a singleton cuz of parse_string
|
71
|
+
# either way, only do it once per tilt/cs obj, unless you don't wanna
|
72
|
+
@already_parsed = true
|
73
|
+
@engine.parse_string @data # CS C API
|
74
|
+
end
|
75
|
+
else
|
76
|
+
debug { "#3" }
|
77
|
+
@engine = Neo::Cs.new # CS Ruby API, revamped
|
78
|
+
@engine.use hd # CS Ruby/C API
|
79
|
+
@engine.parse_string @data # CS C API
|
80
|
+
end
|
81
|
+
@output = @engine.render # it's actually called render in CS C API
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
Tilt.register Tilt::ClearSilverTemplate, 'cshtml'
|
data/tarpaulin.gemspec
ADDED
@@ -0,0 +1,72 @@
|
|
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 = "tarpaulin"
|
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 = ["Anthony Durity"]
|
12
|
+
s.date = "2011-10-13"
|
13
|
+
s.description = "So I don't have to copy and paste a million times."
|
14
|
+
s.email = "github@jollyrotten.org"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"bivouac.gemspec",
|
27
|
+
"lib/tarpaulin.rb",
|
28
|
+
"lib/tarpaulin/camping.rb",
|
29
|
+
"lib/tarpaulin/endless.rb",
|
30
|
+
"lib/tarpaulin/logger.rb",
|
31
|
+
"lib/tarpaulin/tilt/clearsilver_template.rb",
|
32
|
+
"tarpaulin.gemspec",
|
33
|
+
"test/helper.rb",
|
34
|
+
"test/test_kommons.rb"
|
35
|
+
]
|
36
|
+
s.homepage = "http://github.com/igravious/tarpaulin"
|
37
|
+
s.licenses = ["GPLv3"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = "1.8.11"
|
40
|
+
s.summary = "Useful Camping and Web app helper methods"
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_runtime_dependency(%q<tilt>, ["~> 1.3.1"])
|
47
|
+
s.add_runtime_dependency(%q<lazy>, ["~> 0.9.6"])
|
48
|
+
s.add_development_dependency(%q<shoulda>, ["~> 2.11.1"])
|
49
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.1"])
|
51
|
+
s.add_development_dependency(%q<rcov>, ["~> 0.9.7"])
|
52
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.9.1"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<tilt>, ["~> 1.3.1"])
|
55
|
+
s.add_dependency(%q<lazy>, ["~> 0.9.6"])
|
56
|
+
s.add_dependency(%q<shoulda>, ["~> 2.11.1"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.1"])
|
59
|
+
s.add_dependency(%q<rcov>, ["~> 0.9.7"])
|
60
|
+
s.add_dependency(%q<rdoc>, ["~> 3.9.1"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<tilt>, ["~> 1.3.1"])
|
64
|
+
s.add_dependency(%q<lazy>, ["~> 0.9.6"])
|
65
|
+
s.add_dependency(%q<shoulda>, ["~> 2.11.1"])
|
66
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.1"])
|
68
|
+
s.add_dependency(%q<rcov>, ["~> 0.9.7"])
|
69
|
+
s.add_dependency(%q<rdoc>, ["~> 3.9.1"])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'tarpaulin'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tarpaulin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Anthony Durity
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-13 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
prerelease: false
|
22
|
+
name: tilt
|
23
|
+
type: :runtime
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 25
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 3
|
33
|
+
- 1
|
34
|
+
version: 1.3.1
|
35
|
+
requirement: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
prerelease: false
|
38
|
+
name: lazy
|
39
|
+
type: :runtime
|
40
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 55
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 9
|
49
|
+
- 6
|
50
|
+
version: 0.9.6
|
51
|
+
requirement: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
prerelease: false
|
54
|
+
name: shoulda
|
55
|
+
type: :development
|
56
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 33
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 11
|
65
|
+
- 1
|
66
|
+
version: 2.11.1
|
67
|
+
requirement: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
prerelease: false
|
70
|
+
name: bundler
|
71
|
+
type: :development
|
72
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 23
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 0
|
81
|
+
- 0
|
82
|
+
version: 1.0.0
|
83
|
+
requirement: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
prerelease: false
|
86
|
+
name: jeweler
|
87
|
+
type: :development
|
88
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 13
|
94
|
+
segments:
|
95
|
+
- 1
|
96
|
+
- 6
|
97
|
+
- 1
|
98
|
+
version: 1.6.1
|
99
|
+
requirement: *id005
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
prerelease: false
|
102
|
+
name: rcov
|
103
|
+
type: :development
|
104
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 53
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
- 9
|
113
|
+
- 7
|
114
|
+
version: 0.9.7
|
115
|
+
requirement: *id006
|
116
|
+
- !ruby/object:Gem::Dependency
|
117
|
+
prerelease: false
|
118
|
+
name: rdoc
|
119
|
+
type: :development
|
120
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
hash: 33
|
126
|
+
segments:
|
127
|
+
- 3
|
128
|
+
- 9
|
129
|
+
- 1
|
130
|
+
version: 3.9.1
|
131
|
+
requirement: *id007
|
132
|
+
description: So I don't have to copy and paste a million times.
|
133
|
+
email: github@jollyrotten.org
|
134
|
+
executables: []
|
135
|
+
|
136
|
+
extensions: []
|
137
|
+
|
138
|
+
extra_rdoc_files:
|
139
|
+
- LICENSE.txt
|
140
|
+
- README.rdoc
|
141
|
+
files:
|
142
|
+
- .document
|
143
|
+
- Gemfile
|
144
|
+
- LICENSE.txt
|
145
|
+
- README.rdoc
|
146
|
+
- Rakefile
|
147
|
+
- VERSION
|
148
|
+
- bivouac.gemspec
|
149
|
+
- lib/tarpaulin.rb
|
150
|
+
- lib/tarpaulin/camping.rb
|
151
|
+
- lib/tarpaulin/endless.rb
|
152
|
+
- lib/tarpaulin/logger.rb
|
153
|
+
- lib/tarpaulin/tilt/clearsilver_template.rb
|
154
|
+
- tarpaulin.gemspec
|
155
|
+
- test/helper.rb
|
156
|
+
- test/test_kommons.rb
|
157
|
+
homepage: http://github.com/igravious/tarpaulin
|
158
|
+
licenses:
|
159
|
+
- GPLv3
|
160
|
+
post_install_message:
|
161
|
+
rdoc_options: []
|
162
|
+
|
163
|
+
require_paths:
|
164
|
+
- lib
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
none: false
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
hash: 3
|
171
|
+
segments:
|
172
|
+
- 0
|
173
|
+
version: "0"
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
none: false
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
hash: 3
|
180
|
+
segments:
|
181
|
+
- 0
|
182
|
+
version: "0"
|
183
|
+
requirements: []
|
184
|
+
|
185
|
+
rubyforge_project:
|
186
|
+
rubygems_version: 1.8.11
|
187
|
+
signing_key:
|
188
|
+
specification_version: 3
|
189
|
+
summary: Useful Camping and Web app helper methods
|
190
|
+
test_files: []
|
191
|
+
|