Capcode 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -310,6 +310,28 @@ If you want to use a specific layout, you can specify it with option
310
310
  </pre>
311
311
  </div>
312
312
  </div>
313
+ <h4 class="ruled">Public Instance method:
314
+ <strong><a name="M000014">static()</a></strong> <a href="#M000014"><img src="../../permalink.gif" border="0" title="Permalink to Public Instance method: static" /></a></h4>
315
+
316
+ <p>
317
+ Return information about the <a href="Helpers.html#M000014">static</a>
318
+ directory
319
+ </p>
320
+
321
+ <div class="sourcecode">
322
+ <p class="source-link">[ <a href="javascript:toggleSource('M000014_source')" id="l_M000014_source">show source</a> ]</p>
323
+ <div id="M000014_source" class="dyn-source">
324
+ <pre>
325
+ <span class="ruby-comment cmt"># File lib/capcode.rb, line 149</span>
326
+ 149: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">static</span>
327
+ 150: {
328
+ 151: <span class="ruby-identifier">:uri</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span>,
329
+ 152: <span class="ruby-identifier">:path</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>( <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;.&quot;</span>, <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">static</span> ) )
330
+ 153: }
331
+ 154: <span class="ruby-keyword kw">end</span>
332
+ </pre>
333
+ </div>
334
+ </div>
313
335
 
314
336
  </div>
315
337
  </div>
@@ -1 +1 @@
1
- Wed, 08 Jul 2009 02:03:05 +0200
1
+ Fri, 17 Jul 2009 18:23:07 +0200
@@ -81,7 +81,7 @@ end</strong>
81
81
  <div id="README" class="page_shade">
82
82
  <div class="page">
83
83
  <div class="header">
84
- <div class="path">README / Wed Jul 08 02:02:45 +0200 2009</div>
84
+ <div class="path">README / Fri Jul 17 18:22:38 +0200 2009</div>
85
85
  </div>
86
86
 
87
87
  <h1><a href="../classes/Capcode.html">Capcode</a></h1>
@@ -98,6 +98,25 @@ Copyright (C) 2009 Gregoire Lejeune
98
98
  <a href="../classes/Capcode.html">Capcode</a> is a web microframework
99
99
  </p>
100
100
  <h2>FEATURES/PROBLEMS:</h2>
101
+ <h3>0.8.2</h3>
102
+ <ul>
103
+ <li>Add XML renderer (see rss example)
104
+
105
+ </li>
106
+ <li>Major bug corrections
107
+
108
+ </li>
109
+ <li>Add Helpers.static
110
+
111
+ </li>
112
+ <li>New example : upload.rb
113
+
114
+ </li>
115
+ <li>The database&#8217; configuration file is no more relative to the root
116
+ directory but to the main file
117
+
118
+ </li>
119
+ </ul>
101
120
  <h3>0.8.1</h3>
102
121
  <ul>
103
122
  <li>Sorry for 0.8.0 !!
@@ -196,7 +215,7 @@ href="../classes/Capcode.html#M000008">Capcode.run</a>. This option allow
196
215
  you to specify the working directory
197
216
 
198
217
  </li>
199
- <li>Of &#8217;/&#8217; route is not defined but /index.html exist, display
218
+ <li>If &#8217;/&#8217; route is not defined but /index.html exist, display
200
219
  index
201
220
 
202
221
  </li>
@@ -81,7 +81,7 @@ end</strong>
81
81
  <div id="lib/capcode.rb" class="page_shade">
82
82
  <div class="page">
83
83
  <div class="header">
84
- <div class="path">lib/capcode.rb / Wed Jul 08 02:02:06 +0200 2009</div>
84
+ <div class="path">lib/capcode.rb / Fri Jul 17 12:19:44 +0200 2009</div>
85
85
  </div>
86
86
 
87
87
  <pre>
@@ -0,0 +1,48 @@
1
+ $:.unshift( "../lib" )
2
+ require 'rubygems'
3
+ require 'capcode'
4
+ require 'capcode/render/xml'
5
+
6
+ ## !! THIS IS JUSTE FOR THIS EXAMPLE !!
7
+ class Hash
8
+ def method_missing( id, *a )
9
+ self[id.id2name.to_sym]
10
+ end
11
+ end
12
+
13
+ module Capcode
14
+ class RSS < Route "/rss"
15
+ def get
16
+ @posts = [
17
+ { :title => "Welcome", :body => "This is a RSS example for Capcode!", :iid => 1, :created_at => Time.now() },
18
+ { :title => "Just For Fun", :body => "See more examples on the Capcode Website...", :iid => 2, :created_at => Time.now() },
19
+ ]
20
+ render :xml => :rss_view
21
+ end
22
+ end
23
+ end
24
+
25
+ module Capcode::Views
26
+ def rss_view
27
+ xml? :version => '1.0'
28
+ rss :version => "2.0" do
29
+ channel do
30
+ title "Capcode News"
31
+ description "Capcode Framework."
32
+ link "http://example.com/"
33
+
34
+ @posts.each do |post|
35
+ item do
36
+ title post.title
37
+ link "http://example.com/posts/#{post.iid}"
38
+ description post.body
39
+ pubDate Time.parse(post.created_at.to_s).rfc822()
40
+ guid "http://example.com/posts/#{post.iid}"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ Capcode.run()
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'capcode'
3
+ require 'capcode/render/markaby'
4
+ require 'capcode/render/static'
5
+ require 'fileutils'
6
+
7
+ module Capcode
8
+ class Index < Route '/'
9
+ def get
10
+ render :markaby => :index
11
+ end
12
+
13
+ def post
14
+ FileUtils.cp(
15
+ params["upfile"][:tempfile].path,
16
+ File.join( static[:path], params["upfile"][:filename] )
17
+ )
18
+ render :static => params["upfile"][:filename]
19
+ end
20
+ end
21
+ end
22
+
23
+ module Capcode::Views
24
+ def index
25
+ html do
26
+ body do
27
+ h1 "Upload..."
28
+ form :method => "POST", :enctype => 'multipart/form-data' do
29
+ input :type => "file", :name => "upfile"; br
30
+ input :type => "submit", :value => "Upload"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ FileUtils.mkdir_p 'data'
38
+
39
+ Capcode.run( :static => "data" )
@@ -144,6 +144,14 @@ module Capcode
144
144
  yield
145
145
  end
146
146
  end
147
+
148
+ # Return information about the static directory
149
+ def static
150
+ {
151
+ :uri => Capcode.static,
152
+ :path => File.expand_path( File.join(".", Capcode.static ) )
153
+ }
154
+ end
147
155
  end
148
156
 
149
157
  include Rack
@@ -356,7 +364,7 @@ module Capcode
356
364
  :session => args[:session]||{},
357
365
  :pid => args[:pid]||"#{$0}.pid",
358
366
  :daemonize => args[:daemonize]||false,
359
- :db_config => args[:db_config]||"database.yml",
367
+ :db_config => File.expand_path(args[:db_config]||"database.yml"),
360
368
  :static => args[:static]||nil,
361
369
  :root => args[:root]||File.expand_path(File.dirname($0)),
362
370
 
@@ -442,7 +450,7 @@ module Capcode
442
450
  end
443
451
 
444
452
  # Set Static directory
445
- @@__STATIC_DIR = File.expand_path(File.join("/", conf[:static])) unless conf[:static].nil?
453
+ @@__STATIC_DIR = (conf[:static][0].chr == "/")?conf[:static]:"/"+conf[:static] unless conf[:static].nil?
446
454
 
447
455
  # Initialize Rack App
448
456
  puts "** Map routes." if __VERBOSE
@@ -12,6 +12,10 @@ module Capcode
12
12
  end
13
13
 
14
14
  def render_erb( f, opts ) #:nodoc:
15
+ if @@__ERB_PATH__.nil?
16
+ @@__ERB_PATH__ = "." + (Capcode.static.nil? == false)?Capcode.static:''
17
+ end
18
+
15
19
  f = f.to_s
16
20
  if f.include? '..'
17
21
  return [403, {}, '403 - Invalid path']
@@ -2,12 +2,16 @@ require "haml"
2
2
 
3
3
  module Capcode
4
4
  module Helpers
5
- @@__HAML_PATH__ = "."
5
+ @@__HAML_PATH__ = nil
6
6
  def self.haml_path=( p )
7
7
  @@__HAML_PATH__ = p
8
8
  end
9
9
 
10
10
  def render_haml( f, opts ) #:nodoc:
11
+ if @@__HAML_PATH__.nil?
12
+ @@__HAML_PATH__ = "." + (Capcode.static.nil? == false)?Capcode.static:''
13
+ end
14
+
11
15
  f = f.to_s
12
16
  if f.include? '..'
13
17
  return [403, {}, '403 - Invalid path']
@@ -8,6 +8,10 @@ module Capcode
8
8
  end
9
9
 
10
10
  def render_sass( f, _ ) #:nodoc:
11
+ if @@__SASS_PATH__.nil?
12
+ @@__SASS_PATH__ = "." + (Capcode.static.nil? == false)?Capcode.static:''
13
+ end
14
+
11
15
  f = f.to_s
12
16
  if f.include? '..'
13
17
  return [403, {}, '403 - Invalid path']
@@ -1,8 +1,8 @@
1
1
  module Capcode
2
2
  module Helpers
3
3
  def render_static( f, _ )
4
- if Capcode.static.nil?
5
- return [404, {}, ""]
4
+ if Capcode.static.nil? or f.include? '..'
5
+ return [403, {}, '403 - Invalid path']
6
6
  end
7
7
  redirect File.join( Capcode.static, f )
8
8
  end
@@ -0,0 +1,121 @@
1
+ # To use the XML renderer, you first need to require 'capcode/render/xml'
2
+
3
+ class XML #:nodoc:
4
+ class TagError < ArgumentError #:nodoc:
5
+ end
6
+
7
+ class DSL #:nodoc:
8
+ def initialize( helper, &block )
9
+ @__x_d_level = 0
10
+ @__x_d_helper = helper
11
+ @__x_d_helper.instance_variables.each do |ivar|
12
+ self.instance_variable_set(ivar, @__x_d_helper.instance_variable_get(ivar))
13
+ end
14
+ @__x_d_builder = ""
15
+ instance_eval(&block) if block
16
+ end
17
+
18
+ def __
19
+ " "*@__x_d_level
20
+ end
21
+
22
+ def _(x)
23
+ @__x_d_builder << __ << x << "\n"
24
+ end
25
+
26
+ def tag!(sym, *args, &block)
27
+ tag = {
28
+ :bra => "<",
29
+ :ket => " />",
30
+ :name => sym.id2name,
31
+ :close => block_given?(),
32
+ :attrs => "",
33
+ :value => ""
34
+ }
35
+
36
+ args.each do |a|
37
+ if a.class == Hash
38
+ a.each do |k, v|
39
+ tag[:attrs] << " #{k.to_s}='#{v}'"
40
+ end
41
+ elsif a.class == String
42
+ tag[:close] = true
43
+ tag[:value] << a << "\n"
44
+ end
45
+ end
46
+
47
+ if tag[:name].match( /\?$/ )
48
+ tag[:name].gsub!( /\?$/, "" )
49
+ tag[:bra] = "<?"
50
+ tag[:ket] = "?>"
51
+
52
+ if tag[:close] == true
53
+ raise XML::TagError, "Malformated traitment tag!"
54
+ end
55
+ end
56
+
57
+ @__x_d_builder << __ << tag[:bra] << "#{tag[:name]}#{tag[:attrs]}"
58
+ if tag[:close]
59
+ @__x_d_builder << ">\n"
60
+ else
61
+ @__x_d_builder << tag[:ket] << "\n"
62
+ end
63
+
64
+ @__x_d_level += 2
65
+
66
+ @__x_d_builder << __ << tag[:value] if tag[:value].size > 0
67
+ instance_eval(&block) if block
68
+
69
+ @__x_d_level -= 2
70
+
71
+ if tag[:close]
72
+ @__x_d_builder << __ << "</#{tag[:name]}>\n"
73
+ end
74
+ end
75
+
76
+ def cdata( x = "", &block )
77
+ @__x_d_builder << __ << "<![CDATA["
78
+ if x.match( /\n/ ) or block
79
+ @__x_d_level += 2
80
+ @__x_d_builder << "\n" << __ << x << "\n" if x.size > 0
81
+ instance_eval(&block) if block
82
+ @__x_d_level -= 2
83
+ @__x_d_builder << __
84
+ else
85
+ @__x_d_builder << x if x.size > 0
86
+ end
87
+ @__x_d_builder << "]]>\n"
88
+ end
89
+
90
+ def to_s
91
+ @__x_d_builder
92
+ end
93
+
94
+ def method_missing(sym, *args, &block)
95
+ if @__x_d_helper.respond_to?(sym, true)
96
+ @__x_d_helper.send(sym, *args, &block)
97
+ elsif instance_variables.include?(ivar = "@__x_d_#{sym}")
98
+ instance_variable_get(ivar)
99
+ elsif !@__x_d_helper.nil? && @__x_d_helper.instance_variables.include?(ivar)
100
+ @__x_d_helper.instance_variable_get(ivar)
101
+ else
102
+ tag!(sym, *args, &block)
103
+ end
104
+ end
105
+ end
106
+ end
107
+
108
+ module Capcode
109
+ class XML::DSL #:nodoc:
110
+ include Views
111
+ end
112
+
113
+ module Helpers
114
+ def render_xml( f, _ ) #:nodoc:
115
+ r = XML::DSL.new( self ) do
116
+ self.send(f.to_s)
117
+ end
118
+ r.to_s
119
+ end
120
+ end
121
+ end
@@ -1,3 +1,3 @@
1
1
  module Capcode
2
- CAPCOD_VERION="0.8.1"
2
+ CAPCOD_VERION="0.8.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Capcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Gr\xC3\xA9goire Lejeune"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-08 00:00:00 +02:00
12
+ date: 2009-07-17 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -107,6 +107,7 @@ files:
107
107
  - lib/capcode/render/sass.rb
108
108
  - lib/capcode/render/static.rb
109
109
  - lib/capcode/render/text.rb
110
+ - lib/capcode/render/xml.rb
110
111
  - lib/capcode/version.rb
111
112
  - lib/capcode.rb
112
113
  - examples/blog-couchdb.rb
@@ -122,10 +123,12 @@ files:
122
123
  - examples/haml/layout.haml
123
124
  - examples/haml/m_hello.haml
124
125
  - examples/my_blog.db
126
+ - examples/rss.rb
125
127
  - examples/sample.rb
126
128
  - examples/session.rb
127
129
  - examples/static/index.html
128
130
  - examples/test/index.html
131
+ - examples/upload.rb
129
132
  has_rdoc: true
130
133
  homepage: http://algorithmique.net
131
134
  licenses: []
@@ -134,9 +137,14 @@ post_install_message: |+
134
137
 
135
138
  If you want to use Markaby renderer, you must install Markaby.
136
139
  If you want to use HAML renderer, you must install haml.
140
+ If you want to use SASS renderer, you must install sass.
141
+ If you want to use JSON renderer, you must install json
137
142
 
138
143
  If For more information about Capcode, see
139
- http://capcode.rubyforge.org"
144
+ http://capcode.rubyforge.org
145
+
146
+ You can also read the Capcode book (fr) at
147
+ http://algorithmique.net/capcode
140
148
 
141
149
  rdoc_options:
142
150
  - --quiet