capcode-render-static 0.1.0

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 glejeune
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,3 @@
1
+ = capcode-render-static
2
+
3
+ Capcode plugin to render static file
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "capcode-render-static"
8
+ gem.summary = %Q{Capcode plugin to render static file}
9
+ gem.description = gem.summary
10
+ gem.email = "gregoire.lejeune@free.fr"
11
+ gem.homepage = "http://github.com/glejeune/Capcode.more/tree/master/%s" % gem.name
12
+ gem.authors = ["Gregoire Lejeune"]
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
17
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,47 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{capcode-render-static}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Gregoire Lejeune"]
12
+ s.date = %q{2010-01-06}
13
+ s.description = %q{Capcode plugin to render static file}
14
+ s.email = %q{gregoire.lejeune@free.fr}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "capcode-render-static.gemspec",
24
+ "examples/render-static.rb",
25
+ "examples/render-static.ru",
26
+ "examples/render-use.rb",
27
+ "examples/static/coderay.css",
28
+ "examples/static/index.html",
29
+ "lib/capcode/render/static.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/glejeune/Capcode.more/tree/master/capcode-render-static}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{Capcode plugin to render static file}
36
+
37
+ if s.respond_to? :specification_version then
38
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
42
+ else
43
+ end
44
+ else
45
+ end
46
+ end
47
+
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'capcode'
3
+ $:.unshift( "../lib" )
4
+ require 'capcode/render/static'
5
+
6
+ module Capcode
7
+ set :static, "static"
8
+ set :verbose, true
9
+
10
+ class Index < Route '/'
11
+ def get
12
+ render :static => "index.html"
13
+ end
14
+ end
15
+ class Path < Route '/path'
16
+ def get
17
+ render :static => "index.html", :exact_path => false
18
+ end
19
+ end
20
+ end
21
+
22
+ Capcode.run( )
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'capcode'
3
+ $:.unshift( "../lib" )
4
+ require 'capcode/render/static'
5
+
6
+ module Capcode
7
+ class Index < Route '/'
8
+ def get
9
+ render :static => "index.html"
10
+ end
11
+ end
12
+ class Path < Route '/path'
13
+ def get
14
+ render :static => "index.html", :exact_path => false
15
+ end
16
+ end
17
+ end
18
+
19
+ ## WARNING : when using rackup, :root default is the rackup directory (eg. /usr/bin or something like that) !
20
+ run Capcode.application( :static => "static", :verbose => true, :root => File.expand_path(File.dirname(__FILE__)) )
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'capcode'
3
+ require 'coderay'
4
+ require 'rack/codehighlighter'
5
+ $:.unshift( "../lib" )
6
+ require 'capcode/render/static'
7
+
8
+ module Capcode
9
+ set :static, "static"
10
+ set :verbose, true
11
+ set :server, :thin
12
+
13
+ use Rack::Codehighlighter, :coderay, :element => "pre", :pattern => /\A:::(\w+)\s*\n/, :logging => false
14
+
15
+ class Index < Route '/'
16
+ def get
17
+ render :static => "index.html"
18
+ end
19
+ end
20
+ class Path < Route '/path'
21
+ def get
22
+ render :static => "index.html", :exact_path => false
23
+ end
24
+ end
25
+ class Style < Route '/style'
26
+ def get
27
+ render :static => "coderay.css", :exact_path => false
28
+ end
29
+ end
30
+ end
31
+
32
+ Capcode.run( )
@@ -0,0 +1,131 @@
1
+ .CodeRay {
2
+ background-color: #f8f8f8;
3
+ border: 1px solid silver;
4
+ font-family: 'Courier New', 'Terminal', monospace;
5
+ color: #000;
6
+ }
7
+ .CodeRay pre { margin: 0px }
8
+
9
+ div.CodeRay { }
10
+
11
+ span.CodeRay { white-space: pre; border: 0px; padding: 2px }
12
+
13
+ table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
14
+ table.CodeRay td { padding: 2px 4px; vertical-align: top }
15
+
16
+ .CodeRay .line_numbers, .CodeRay .no {
17
+ background-color: #def;
18
+ color: gray;
19
+ text-align: right;
20
+ }
21
+ .CodeRay .line_numbers tt { font-weight: bold }
22
+ .CodeRay .line_numbers .highlighted { color: red }
23
+ .CodeRay .no { padding: 0px 4px }
24
+ .CodeRay .code { width: 100% }
25
+
26
+ ol.CodeRay { font-size: 10pt }
27
+ ol.CodeRay li { white-space: pre }
28
+
29
+ .CodeRay .code pre { overflow: auto }
30
+
31
+ .CodeRay .debug { color:white ! important; background:blue ! important; }
32
+
33
+ .CodeRay .af { color:#00C }
34
+ .CodeRay .an { color:#007 }
35
+ .CodeRay .at { color:#f08 }
36
+ .CodeRay .av { color:#700 }
37
+ .CodeRay .aw { color:#C00 }
38
+ .CodeRay .bi { color:#509; font-weight:bold }
39
+ .CodeRay .c { color:#888; }
40
+
41
+ .CodeRay .ch { color:#04D }
42
+ .CodeRay .ch .k { color:#04D }
43
+ .CodeRay .ch .dl { color:#039 }
44
+
45
+ .CodeRay .cl { color:#B06; font-weight:bold }
46
+ .CodeRay .cm { color:#A08; font-weight:bold }
47
+ .CodeRay .co { color:#036; font-weight:bold }
48
+ .CodeRay .cr { color:#0A0 }
49
+ .CodeRay .cv { color:#369 }
50
+ .CodeRay .de { color:#B0B; }
51
+ .CodeRay .df { color:#099; font-weight:bold }
52
+ .CodeRay .di { color:#088; font-weight:bold }
53
+ .CodeRay .dl { color:black }
54
+ .CodeRay .do { color:#970 }
55
+ .CodeRay .dt { color:#34b }
56
+ .CodeRay .ds { color:#D42; font-weight:bold }
57
+ .CodeRay .e { color:#666; font-weight:bold }
58
+ .CodeRay .en { color:#800; font-weight:bold }
59
+ .CodeRay .er { color:#F00; background-color:#FAA }
60
+ .CodeRay .ex { color:#F00; font-weight:bold }
61
+ .CodeRay .fl { color:#60E; font-weight:bold }
62
+ .CodeRay .fu { color:#06B; font-weight:bold }
63
+ .CodeRay .gv { color:#d70; font-weight:bold }
64
+ .CodeRay .hx { color:#058; font-weight:bold }
65
+ .CodeRay .i { color:#00D; font-weight:bold }
66
+ .CodeRay .ic { color:#B44; font-weight:bold }
67
+
68
+ .CodeRay .il { background: #ddd; color: black }
69
+ .CodeRay .il .il { background: #ccc }
70
+ .CodeRay .il .il .il { background: #bbb }
71
+ .CodeRay .il .idl { background: #ddd; font-weight: bold; color: #666 }
72
+ .CodeRay .idl { background-color: #bbb; font-weight: bold; color: #666; }
73
+
74
+ .CodeRay .im { color:#f00; }
75
+ .CodeRay .in { color:#B2B; font-weight:bold }
76
+ .CodeRay .iv { color:#33B }
77
+ .CodeRay .la { color:#970; font-weight:bold }
78
+ .CodeRay .lv { color:#963 }
79
+ .CodeRay .oc { color:#40E; font-weight:bold }
80
+ .CodeRay .of { color:#000; font-weight:bold }
81
+ .CodeRay .op { }
82
+ .CodeRay .pc { color:#038; font-weight:bold }
83
+ .CodeRay .pd { color:#369; font-weight:bold }
84
+ .CodeRay .pp { color:#579; }
85
+ .CodeRay .ps { color:#00C; font-weight: bold; }
86
+ .CodeRay .pt { color:#349; font-weight:bold }
87
+ .CodeRay .r, .kw { color:#080; font-weight:bold }
88
+
89
+ .CodeRay .ke { color: #808; }
90
+ .CodeRay .ke .dl { color: #606; }
91
+ .CodeRay .ke .ch { color: #80f; }
92
+ .CodeRay .vl { color: #088; }
93
+
94
+ .CodeRay .rx { background-color:#fff0ff }
95
+ .CodeRay .rx .k { color:#808 }
96
+ .CodeRay .rx .dl { color:#404 }
97
+ .CodeRay .rx .mod { color:#C2C }
98
+ .CodeRay .rx .fu { color:#404; font-weight: bold }
99
+
100
+ .CodeRay .s { background-color:#fff0f0; color: #D20; }
101
+ .CodeRay .s .s { background-color:#ffe0e0 }
102
+ .CodeRay .s .s .s { background-color:#ffd0d0 }
103
+ .CodeRay .s .k { }
104
+ .CodeRay .s .ch { color: #b0b; }
105
+ .CodeRay .s .dl { color: #710; }
106
+
107
+ .CodeRay .sh { background-color:#f0fff0; color:#2B2 }
108
+ .CodeRay .sh .k { }
109
+ .CodeRay .sh .dl { color:#161 }
110
+
111
+ .CodeRay .sy { color:#A60 }
112
+ .CodeRay .sy .k { color:#A60 }
113
+ .CodeRay .sy .dl { color:#630 }
114
+
115
+ .CodeRay .ta { color:#070 }
116
+ .CodeRay .tf { color:#070; font-weight:bold }
117
+ .CodeRay .ts { color:#D70; font-weight:bold }
118
+ .CodeRay .ty { color:#339; font-weight:bold }
119
+ .CodeRay .v { color:#036 }
120
+ .CodeRay .xt { color:#444 }
121
+
122
+ .CodeRay .ins { background: #afa; }
123
+ .CodeRay .del { background: #faa; }
124
+ .CodeRay .chg { color: #aaf; background: #007; }
125
+ .CodeRay .head { color: #f8f; background: #505 }
126
+
127
+ .CodeRay .ins .ins { color: #080; font-weight:bold }
128
+ .CodeRay .del .del { color: #800; font-weight:bold }
129
+ .CodeRay .chg .chg { color: #66f; }
130
+ .CodeRay .head .head { color: #f4f; }
131
+
@@ -0,0 +1,24 @@
1
+ <html>
2
+ <head>
3
+ <link href="/style" media="screen" rel="Stylesheet" type="text/css" />
4
+ </head>
5
+ <body>
6
+ <h1>Capcode hello !</h1>
7
+
8
+ <p>
9
+ Code :
10
+ <pre>:::ruby
11
+ # In an object instance variable (denoted with '@'), remember a block.
12
+ def remember(&a_block)
13
+ @block = a_block
14
+ end
15
+
16
+ # Invoke the above method, giving it a block which takes a name.
17
+ remember {|name| puts "Hello, #{name}!"}
18
+
19
+ # When the time is right (for the object) -- call the closure!
20
+ @block.call("Jon")
21
+ # => "Hello, Jon!"</pre>
22
+ </p>
23
+ </body>
24
+ </html>
@@ -0,0 +1,24 @@
1
+ module Capcode
2
+ module Helpers
3
+ def render_static( f, opts = {} ) #:nodoc:
4
+ # Update options
5
+ opts = { :exact_path => true }.merge(opts)
6
+ opts = (Capcode.options[:static] || {}).merge(opts)
7
+
8
+ # Update Content-Type
9
+ @response['Content-Type'] = opts[:content_type] if opts.keys.include?(:content_type)
10
+
11
+ # Path with ".." not allowed
12
+ if Capcode.static.nil? or f.include? '..'
13
+ return [403, {}, '403 - Invalid path']
14
+ end
15
+
16
+
17
+ if !opts.keys.include?(:exact_path) or opts[:exact_path] == true
18
+ redirect File.join( static[:uri], f )
19
+ else
20
+ File.read( File.join( static[:path], f ) ).to_s
21
+ end
22
+ end
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capcode-render-static
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gregoire Lejeune
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-06 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Capcode plugin to render static file
17
+ email: gregoire.lejeune@free.fr
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - LICENSE
26
+ - README.rdoc
27
+ - Rakefile
28
+ - VERSION
29
+ - capcode-render-static.gemspec
30
+ - examples/render-static.rb
31
+ - examples/render-static.ru
32
+ - examples/render-use.rb
33
+ - examples/static/coderay.css
34
+ - examples/static/index.html
35
+ - lib/capcode/render/static.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/glejeune/Capcode.more/tree/master/capcode-render-static
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Capcode plugin to render static file
64
+ test_files: []
65
+