Capcode 0.1.0 → 0.2.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/README +22 -0
- data/doc/rdoc/classes/Capcode.html +207 -168
- data/doc/rdoc/classes/Capcode/HTTPError.html +1 -0
- data/doc/rdoc/classes/Capcode/Helpers.html +25 -24
- data/doc/rdoc/classes/Capcode/ParameterError.html +1 -0
- data/doc/rdoc/classes/Capcode/RouteError.html +126 -0
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/AUTHORS.html +1 -0
- data/doc/rdoc/files/COPYING.html +1 -0
- data/doc/rdoc/files/README.html +33 -1
- data/doc/rdoc/files/lib/capcode_rb.html +3 -1
- data/examples/{blog.rb → blog-couchdb.rb} +5 -5
- data/examples/blog-couchdb.yml +2 -0
- data/examples/blog-dm.rb +63 -0
- data/examples/blog-dm.yml +2 -0
- data/examples/my_blog.db +0 -0
- data/lib/capcode.rb +40 -3
- data/lib/capcode/base/couchdb.rb +18 -0
- data/lib/capcode/base/dm.rb +28 -0
- data/lib/capcode/core_ext.rb +9 -0
- data/lib/capcode/version.rb +3 -0
- metadata +12 -4
- data/examples/blog.log +0 -16
| @@ -68,6 +68,7 @@ | |
| 68 68 | 
             
            <a href="../../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
         | 
| 69 69 | 
             
            <a href="../../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
         | 
| 70 70 | 
             
            <a href="../../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
         | 
| 71 | 
            +
            <a href="../../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
         | 
| 71 72 | 
             
            <a href="../../classes/Capcode/ParameterError.html" title="Class: Capcode::ParameterError">Capcode::ParameterError</a>.view_html<br />
         | 
| 72 73 | 
             
            end</strong>
         | 
| 73 74 | 
             
            </td></tr>
         | 
| @@ -68,6 +68,7 @@ | |
| 68 68 | 
             
            <a href="../../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
         | 
| 69 69 | 
             
            <a href="../../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
         | 
| 70 70 | 
             
            <a href="../../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
         | 
| 71 | 
            +
            <a href="../../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
         | 
| 71 72 | 
             
            <a href="../../classes/Capcode/ParameterError.html" title="Class: Capcode::ParameterError">Capcode::ParameterError</a>.view_html<br />
         | 
| 72 73 | 
             
            end</strong>
         | 
| 73 74 | 
             
            </td></tr>
         | 
| @@ -127,21 +128,21 @@ then | |
| 127 128 | 
             
              <p class="source-link">[ <a href="javascript:toggleSource('M000011_source')" id="l_M000011_source">show source</a> ]</p>
         | 
| 128 129 | 
             
              <div id="M000011_source" class="dyn-source">
         | 
| 129 130 | 
             
            <pre>
         | 
| 130 | 
            -
                <span class="ruby-comment cmt"># File lib/capcode.rb, line  | 
| 131 | 
            -
             | 
| 132 | 
            -
             | 
| 133 | 
            -
             | 
| 134 | 
            -
             | 
| 135 | 
            -
             | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 138 | 
            -
             | 
| 139 | 
            -
             | 
| 140 | 
            -
             | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 143 | 
            -
             | 
| 144 | 
            -
             | 
| 131 | 
            +
                <span class="ruby-comment cmt"># File lib/capcode.rb, line 63</span>
         | 
| 132 | 
            +
            63:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">URL</span>( <span class="ruby-identifier">klass</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">a</span> )
         | 
| 133 | 
            +
            64:       <span class="ruby-identifier">path</span> = <span class="ruby-keyword kw">nil</span>
         | 
| 134 | 
            +
            65:       <span class="ruby-identifier">a</span> = <span class="ruby-identifier">a</span>.<span class="ruby-identifier">delete_if</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">nil?</span> }
         | 
| 135 | 
            +
            66:       
         | 
| 136 | 
            +
            67:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Class</span>
         | 
| 137 | 
            +
            68:         <span class="ruby-constant">Capcode</span>.<span class="ruby-identifier">routes</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">p</span>, <span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
         | 
| 138 | 
            +
            69:           <span class="ruby-identifier">path</span> = <span class="ruby-identifier">p</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">klass</span>
         | 
| 139 | 
            +
            70:         <span class="ruby-keyword kw">end</span>
         | 
| 140 | 
            +
            71:       <span class="ruby-keyword kw">else</span>
         | 
| 141 | 
            +
            72:         <span class="ruby-identifier">path</span> = <span class="ruby-identifier">klass</span>
         | 
| 142 | 
            +
            73:       <span class="ruby-keyword kw">end</span>
         | 
| 143 | 
            +
            74:       
         | 
| 144 | 
            +
            75:       <span class="ruby-identifier">path</span><span class="ruby-operator">+</span>((<span class="ruby-identifier">a</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">></span><span class="ruby-value">0</span>)<span class="ruby-operator">?</span>(<span class="ruby-value str">"/"</span><span class="ruby-operator">+</span><span class="ruby-identifier">a</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">"/"</span>))<span class="ruby-operator">:</span>(<span class="ruby-value str">""</span>))
         | 
| 145 | 
            +
            76:     <span class="ruby-keyword kw">end</span>
         | 
| 145 146 | 
             
            </pre>
         | 
| 146 147 | 
             
              </div>
         | 
| 147 148 | 
             
            </div>
         | 
| @@ -165,11 +166,11 @@ Help you to return a JSON response | |
| 165 166 | 
             
              <p class="source-link">[ <a href="javascript:toggleSource('M000009_source')" id="l_M000009_source">show source</a> ]</p>
         | 
| 166 167 | 
             
              <div id="M000009_source" class="dyn-source">
         | 
| 167 168 | 
             
            <pre>
         | 
| 168 | 
            -
                <span class="ruby-comment cmt"># File lib/capcode.rb, line  | 
| 169 | 
            -
             | 
| 170 | 
            -
             | 
| 171 | 
            -
             | 
| 172 | 
            -
             | 
| 169 | 
            +
                <span class="ruby-comment cmt"># File lib/capcode.rb, line 28</span>
         | 
| 170 | 
            +
            28:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">json</span>( <span class="ruby-identifier">d</span> )
         | 
| 171 | 
            +
            29:       <span class="ruby-ivar">@response</span>[<span class="ruby-value str">'Content-Type'</span>] = <span class="ruby-value str">'application/json'</span>
         | 
| 172 | 
            +
            30:       <span class="ruby-identifier">d</span>.<span class="ruby-identifier">to_json</span>
         | 
| 173 | 
            +
            31:     <span class="ruby-keyword kw">end</span>
         | 
| 173 174 | 
             
            </pre>
         | 
| 174 175 | 
             
              </div>
         | 
| 175 176 | 
             
            </div>
         | 
| @@ -197,10 +198,10 @@ Send a <a href="Helpers.html#M000010">redirect</a> response | |
| 197 198 | 
             
              <p class="source-link">[ <a href="javascript:toggleSource('M000010_source')" id="l_M000010_source">show source</a> ]</p>
         | 
| 198 199 | 
             
              <div id="M000010_source" class="dyn-source">
         | 
| 199 200 | 
             
            <pre>
         | 
| 200 | 
            -
                <span class="ruby-comment cmt"># File lib/capcode.rb, line  | 
| 201 | 
            -
             | 
| 202 | 
            -
             | 
| 203 | 
            -
             | 
| 201 | 
            +
                <span class="ruby-comment cmt"># File lib/capcode.rb, line 46</span>
         | 
| 202 | 
            +
            46:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">redirect</span>( <span class="ruby-identifier">klass</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">a</span> )
         | 
| 203 | 
            +
            47:       [<span class="ruby-value">302</span>, {<span class="ruby-value str">'Location'</span> =<span class="ruby-operator">></span> <span class="ruby-constant">URL</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">a</span>)}, <span class="ruby-value str">''</span>]
         | 
| 204 | 
            +
            48:     <span class="ruby-keyword kw">end</span>
         | 
| 204 205 | 
             
            </pre>
         | 
| 205 206 | 
             
              </div>
         | 
| 206 207 | 
             
            </div>
         | 
| @@ -68,6 +68,7 @@ | |
| 68 68 | 
             
            <a href="../../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
         | 
| 69 69 | 
             
            <a href="../../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
         | 
| 70 70 | 
             
            <a href="../../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
         | 
| 71 | 
            +
            <a href="../../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
         | 
| 71 72 | 
             
            <a href="../../classes/Capcode/ParameterError.html" title="Class: Capcode::ParameterError">Capcode::ParameterError</a>.view_html<br />
         | 
| 72 73 | 
             
            end</strong>
         | 
| 73 74 | 
             
            </td></tr>
         | 
| @@ -0,0 +1,126 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
         | 
| 3 | 
            +
            <html>
         | 
| 4 | 
            +
            <head>
         | 
| 5 | 
            +
              <title>
         | 
| 6 | 
            +
              Capcode, the Documentation » Class: Capcode::RouteError
         | 
| 7 | 
            +
              </title>
         | 
| 8 | 
            +
              <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
         | 
| 9 | 
            +
              <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
         | 
| 10 | 
            +
                <script language="JavaScript" type="text/javascript">
         | 
| 11 | 
            +
                // <![CDATA[
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                function toggleSource( id )
         | 
| 14 | 
            +
                {
         | 
| 15 | 
            +
                var elem
         | 
| 16 | 
            +
                var link
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                if( document.getElementById )
         | 
| 19 | 
            +
                {
         | 
| 20 | 
            +
                elem = document.getElementById( id )
         | 
| 21 | 
            +
                link = document.getElementById( "l_" + id )
         | 
| 22 | 
            +
                }
         | 
| 23 | 
            +
                else if ( document.all )
         | 
| 24 | 
            +
                {
         | 
| 25 | 
            +
                elem = eval( "document.all." + id )
         | 
| 26 | 
            +
                link = eval( "document.all.l_" + id )
         | 
| 27 | 
            +
                }
         | 
| 28 | 
            +
                else
         | 
| 29 | 
            +
                return false;
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                if( elem.style.display == "block" )
         | 
| 32 | 
            +
                {
         | 
| 33 | 
            +
                elem.style.display = "none"
         | 
| 34 | 
            +
                link.innerHTML = "show source"
         | 
| 35 | 
            +
                }
         | 
| 36 | 
            +
                else
         | 
| 37 | 
            +
                {
         | 
| 38 | 
            +
                elem.style.display = "block"
         | 
| 39 | 
            +
                link.innerHTML = "hide source"
         | 
| 40 | 
            +
                }
         | 
| 41 | 
            +
                }
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                function openCode( url )
         | 
| 44 | 
            +
                {
         | 
| 45 | 
            +
                window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
         | 
| 46 | 
            +
                }
         | 
| 47 | 
            +
                // ]]>
         | 
| 48 | 
            +
                </script>
         | 
| 49 | 
            +
            </head>
         | 
| 50 | 
            +
            <body>
         | 
| 51 | 
            +
            <!--
         | 
| 52 | 
            +
            <div id="menu">
         | 
| 53 | 
            +
            <h3 class="title">Class: Capcode::RouteError</h3>
         | 
| 54 | 
            +
            </div>
         | 
| 55 | 
            +
            -->
         | 
| 56 | 
            +
            <div id="fullpage">
         | 
| 57 | 
            +
            <div id="pager">
         | 
| 58 | 
            +
            <table>
         | 
| 59 | 
            +
            <tr><td><img src="../../rubyfr.png" /></td>
         | 
| 60 | 
            +
            <td id="pagertd">
         | 
| 61 | 
            +
            <strong># Class: Capcode::RouteError<br />
         | 
| 62 | 
            +
            [
         | 
| 63 | 
            +
            "<a href="../../files/README.html" value="File: README">README</a>", 
         | 
| 64 | 
            +
            "<a href="../../files/AUTHORS.html" value="File: AUTHORS">AUTHORS</a>", 
         | 
| 65 | 
            +
            "<a href="../../files/COPYING.html" value="File: COPYING">COPYING</a>", 
         | 
| 66 | 
            +
            "<a href="../../files/lib/capcode_rb.html" value="File: capcode.rb">lib/capcode.rb</a>", 
         | 
| 67 | 
            +
            <a href="http://greg.rubyfr.net">nil</a>].each do<br /> 
         | 
| 68 | 
            +
            <a href="../../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
         | 
| 69 | 
            +
            <a href="../../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
         | 
| 70 | 
            +
            <a href="../../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
         | 
| 71 | 
            +
            <a href="../../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
         | 
| 72 | 
            +
            <a href="../../classes/Capcode/ParameterError.html" title="Class: Capcode::ParameterError">Capcode::ParameterError</a>.view_html<br />
         | 
| 73 | 
            +
            end</strong>
         | 
| 74 | 
            +
            </td></tr>
         | 
| 75 | 
            +
            </table>
         | 
| 76 | 
            +
            </ul>
         | 
| 77 | 
            +
            </div>
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                
         | 
| 80 | 
            +
            <div id="Capcode::RouteError" class="page_shade">
         | 
| 81 | 
            +
            <div class="page">
         | 
| 82 | 
            +
            <h3>Class Capcode::RouteError < ArgumentError</h3>
         | 
| 83 | 
            +
             | 
| 84 | 
            +
            (in files
         | 
| 85 | 
            +
            <a href="../../files/lib/capcode_rb.html">lib/capcode.rb</a>
         | 
| 86 | 
            +
            )
         | 
| 87 | 
            +
             | 
| 88 | 
            +
            <p>
         | 
| 89 | 
            +
            <a href="HTTPError.html">HTTPError</a> help you to create your own 404, 500
         | 
| 90 | 
            +
            and/or 501 response
         | 
| 91 | 
            +
            </p>
         | 
| 92 | 
            +
            <p>
         | 
| 93 | 
            +
            To create a custom 404 reponse, create a fonction HTTPError.r404 in your
         | 
| 94 | 
            +
            application :
         | 
| 95 | 
            +
            </p>
         | 
| 96 | 
            +
            <pre>
         | 
| 97 | 
            +
              module Capcode
         | 
| 98 | 
            +
                class HTTPError
         | 
| 99 | 
            +
                  def r404(f)
         | 
| 100 | 
            +
                    "#{f} not found :("
         | 
| 101 | 
            +
                  end
         | 
| 102 | 
            +
                end
         | 
| 103 | 
            +
              end
         | 
| 104 | 
            +
            </pre>
         | 
| 105 | 
            +
            <p>
         | 
| 106 | 
            +
            Do the same (r500 and r501) to customize 500 and 501 errors
         | 
| 107 | 
            +
            </p>
         | 
| 108 | 
            +
             | 
| 109 | 
            +
             | 
| 110 | 
            +
             | 
| 111 | 
            +
             | 
| 112 | 
            +
            <h4>Includes</h4>
         | 
| 113 | 
            +
            <ul>
         | 
| 114 | 
            +
            <li>Rack</li>
         | 
| 115 | 
            +
            <li><a href="Capcode/Helpers.html">Capcode::Helpers</a></li>
         | 
| 116 | 
            +
            </ul>
         | 
| 117 | 
            +
             | 
| 118 | 
            +
             | 
| 119 | 
            +
             | 
| 120 | 
            +
            </div>
         | 
| 121 | 
            +
            </div>
         | 
| 122 | 
            +
             | 
| 123 | 
            +
             | 
| 124 | 
            +
            </div>
         | 
| 125 | 
            +
            </body>
         | 
| 126 | 
            +
            </html>
         | 
    
        data/doc/rdoc/created.rid
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            Mon, 16 Mar 2009 12:39:42 +0100
         | 
    
        data/doc/rdoc/files/AUTHORS.html
    CHANGED
    
    | @@ -68,6 +68,7 @@ | |
| 68 68 | 
             
            <a href="../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
         | 
| 69 69 | 
             
            <a href="../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
         | 
| 70 70 | 
             
            <a href="../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
         | 
| 71 | 
            +
            <a href="../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
         | 
| 71 72 | 
             
            <a href="../classes/Capcode/ParameterError.html" title="Class: Capcode::ParameterError">Capcode::ParameterError</a>.view_html<br />
         | 
| 72 73 | 
             
            end</strong>
         | 
| 73 74 | 
             
            </td></tr>
         | 
    
        data/doc/rdoc/files/COPYING.html
    CHANGED
    
    | @@ -68,6 +68,7 @@ | |
| 68 68 | 
             
            <a href="../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
         | 
| 69 69 | 
             
            <a href="../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
         | 
| 70 70 | 
             
            <a href="../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
         | 
| 71 | 
            +
            <a href="../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
         | 
| 71 72 | 
             
            <a href="../classes/Capcode/ParameterError.html" title="Class: Capcode::ParameterError">Capcode::ParameterError</a>.view_html<br />
         | 
| 72 73 | 
             
            end</strong>
         | 
| 73 74 | 
             
            </td></tr>
         | 
    
        data/doc/rdoc/files/README.html
    CHANGED
    
    | @@ -68,6 +68,7 @@ | |
| 68 68 | 
             
            <a href="../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
         | 
| 69 69 | 
             
            <a href="../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
         | 
| 70 70 | 
             
            <a href="../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
         | 
| 71 | 
            +
            <a href="../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
         | 
| 71 72 | 
             
            <a href="../classes/Capcode/ParameterError.html" title="Class: Capcode::ParameterError">Capcode::ParameterError</a>.view_html<br />
         | 
| 72 73 | 
             
            end</strong>
         | 
| 73 74 | 
             
            </td></tr>
         | 
| @@ -78,7 +79,7 @@ end</strong> | |
| 78 79 | 
             
                <div id="README" class="page_shade">
         | 
| 79 80 | 
             
            <div class="page">
         | 
| 80 81 | 
             
            <div class="header">
         | 
| 81 | 
            -
              <div class="path">README /  | 
| 82 | 
            +
              <div class="path">README / Mon Mar 16 12:31:45 +0100 2009</div>
         | 
| 82 83 | 
             
            </div>
         | 
| 83 84 |  | 
| 84 85 | 
             
            <h1><a href="../classes/Capcode.html">Capcode</a></h1>
         | 
| @@ -95,6 +96,18 @@ Copyright (C) 2009 Gregoire Lejeune | |
| 95 96 | 
             
            <a href="../classes/Capcode.html">Capcode</a> is a web microframework
         | 
| 96 97 | 
             
            </p>
         | 
| 97 98 | 
             
            <h2>FEATURES/PROBLEMS:</h2>
         | 
| 99 | 
            +
            <h3>0.2.0</h3>
         | 
| 100 | 
            +
            <ul>
         | 
| 101 | 
            +
            <li>Add models with DataMapper and couch_foo
         | 
| 102 | 
            +
             | 
| 103 | 
            +
            </li>
         | 
| 104 | 
            +
            <li>Add two new options : :daemonize and :pid
         | 
| 105 | 
            +
             | 
| 106 | 
            +
            </li>
         | 
| 107 | 
            +
            <li>Bug correction in Route.
         | 
| 108 | 
            +
             | 
| 109 | 
            +
            </li>
         | 
| 110 | 
            +
            </ul>
         | 
| 98 111 | 
             
            <h3>0.1.0</h3>
         | 
| 99 112 | 
             
            <ul>
         | 
| 100 113 | 
             
            <li>First public release
         | 
| @@ -129,6 +142,25 @@ Copyright (C) 2009 Gregoire Lejeune | |
| 129 142 |  | 
| 130 143 | 
             
            </li>
         | 
| 131 144 | 
             
            </ul>
         | 
| 145 | 
            +
            <h2>Create model</h2>
         | 
| 146 | 
            +
            <pre>
         | 
| 147 | 
            +
                    require 'rubygems'
         | 
| 148 | 
            +
                    require 'capcode'
         | 
| 149 | 
            +
                    require 'capcode/base/dm' # or require 'capcode/base/couchdb'
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                    class Story < Capcode::Base
         | 
| 152 | 
            +
                      include Capcode::Resource
         | 
| 153 | 
            +
             | 
| 154 | 
            +
                      property :id, Integer, :serial => true # only with DataMapper !
         | 
| 155 | 
            +
                      property :title, String
         | 
| 156 | 
            +
                      property :body, String
         | 
| 157 | 
            +
                      property :date, String
         | 
| 158 | 
            +
                    end
         | 
| 159 | 
            +
            </pre>
         | 
| 160 | 
            +
            <p>
         | 
| 161 | 
            +
            See <tt>examples/blog-dm.rb</tt> and/or <tt>examples/blog-couchdb.rb</tt>
         | 
| 162 | 
            +
            for complete examples.
         | 
| 163 | 
            +
            </p>
         | 
| 132 164 | 
             
            <h2>REQUIREMENTS:</h2>
         | 
| 133 165 | 
             
            <ul>
         | 
| 134 166 | 
             
            <li>rack
         | 
| @@ -68,6 +68,7 @@ | |
| 68 68 | 
             
            <a href="../../classes/Capcode.html" title="Module: Capcode">Capcode</a>.view_html<br />
         | 
| 69 69 | 
             
            <a href="../../classes/Capcode/Helpers.html" title="Module: Capcode::Helpers">Capcode::Helpers</a>.view_html<br />
         | 
| 70 70 | 
             
            <a href="../../classes/Capcode/HTTPError.html" title="Class: Capcode::HTTPError">Capcode::HTTPError</a>.view_html<br />
         | 
| 71 | 
            +
            <a href="../../classes/Capcode/RouteError.html" title="Class: Capcode::RouteError">Capcode::RouteError</a>.view_html<br />
         | 
| 71 72 | 
             
            <a href="../../classes/Capcode/ParameterError.html" title="Class: Capcode::ParameterError">Capcode::ParameterError</a>.view_html<br />
         | 
| 72 73 | 
             
            end</strong>
         | 
| 73 74 | 
             
            </td></tr>
         | 
| @@ -78,7 +79,7 @@ end</strong> | |
| 78 79 | 
             
                <div id="lib/capcode.rb" class="page_shade">
         | 
| 79 80 | 
             
            <div class="page">
         | 
| 80 81 | 
             
            <div class="header">
         | 
| 81 | 
            -
              <div class="path">lib/capcode.rb /  | 
| 82 | 
            +
              <div class="path">lib/capcode.rb / Mon Mar 16 12:38:20 +0100 2009</div>
         | 
| 82 83 | 
             
            </div>
         | 
| 83 84 |  | 
| 84 85 | 
             
            <pre>
         | 
| @@ -516,6 +517,7 @@ License instead of this License. | |
| 516 517 | 
             
            <li>rack</li>
         | 
| 517 518 | 
             
            <li>json</li>
         | 
| 518 519 | 
             
            <li>logger</li>
         | 
| 520 | 
            +
            <li>capcode/version</li>
         | 
| 519 521 | 
             
            <li>capcode/core_ext</li>
         | 
| 520 522 | 
             
            <li>mongrel</li>
         | 
| 521 523 | 
             
            </ul>
         | 
| @@ -1,11 +1,11 @@ | |
| 1 1 | 
             
            $:.unshift( "../lib" )
         | 
| 2 2 | 
             
            require 'rubygems'
         | 
| 3 3 | 
             
            require 'capcode'
         | 
| 4 | 
            -
            require ' | 
| 4 | 
            +
            require 'capcode/base/couchdb'
         | 
| 5 5 |  | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 6 | 
            +
            class Story < Capcode::Base
         | 
| 7 | 
            +
              include Capcode::Resource
         | 
| 8 | 
            +
              
         | 
| 9 9 | 
             
              property :title, String
         | 
| 10 10 | 
             
              property :body, String
         | 
| 11 11 | 
             
              property :date, String
         | 
| @@ -59,4 +59,4 @@ module Capcode | |
| 59 59 | 
             
              end
         | 
| 60 60 | 
             
            end
         | 
| 61 61 |  | 
| 62 | 
            -
            Capcode.run( :port => 3001, :host => "localhost", : | 
| 62 | 
            +
            Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-couchdb.yml" )
         | 
    
        data/examples/blog-dm.rb
    ADDED
    
    | @@ -0,0 +1,63 @@ | |
| 1 | 
            +
            $:.unshift( "../lib" )
         | 
| 2 | 
            +
            require 'rubygems'
         | 
| 3 | 
            +
            require 'capcode'
         | 
| 4 | 
            +
            require 'capcode/base/dm'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            class Story < Capcode::Base
         | 
| 7 | 
            +
              include Capcode::Resource
         | 
| 8 | 
            +
              
         | 
| 9 | 
            +
              property :id, Integer, :serial => true
         | 
| 10 | 
            +
              property :title, String
         | 
| 11 | 
            +
              property :body, String
         | 
| 12 | 
            +
              property :date, String
         | 
| 13 | 
            +
            end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            module Capcode
         | 
| 16 | 
            +
              class HTTPError
         | 
| 17 | 
            +
                def r404(f)
         | 
| 18 | 
            +
                  "Pas glop !!! #{f} est inconnu !!!"
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
              
         | 
| 22 | 
            +
              class Index < Route '/'
         | 
| 23 | 
            +
                def get
         | 
| 24 | 
            +
                  r = "<html><body>"
         | 
| 25 | 
            +
                  
         | 
| 26 | 
            +
                  story = Story.all
         | 
| 27 | 
            +
                  
         | 
| 28 | 
            +
                  story.each do |s|
         | 
| 29 | 
            +
                    r += "<h2>#{s.title}</h2><small>#{s.date} - <a href='#{URL( Remove, s.id )}'>Delete this entry</a></small><p>#{s.body}</p>"
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                  
         | 
| 32 | 
            +
                  r+"<hr /><a href='#{URL(Add)}'>Add a new entry</a></body></html>"
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
              
         | 
| 36 | 
            +
              class Remove < Route '/remove/([^\/]*)'
         | 
| 37 | 
            +
                def get( id )
         | 
| 38 | 
            +
                  Story.get!(id).destroy
         | 
| 39 | 
            +
                  redirect( Index )
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
              
         | 
| 43 | 
            +
              class Add < Route '/add'
         | 
| 44 | 
            +
                def get
         | 
| 45 | 
            +
                  '
         | 
| 46 | 
            +
                    <html><body>
         | 
| 47 | 
            +
                      <h1>Add a new entry</h1>
         | 
| 48 | 
            +
                      <form method="POST">
         | 
| 49 | 
            +
                        Titre : <input type="text" name="title"><br />
         | 
| 50 | 
            +
                        <textarea name="body"></textarea><br />
         | 
| 51 | 
            +
                        <input type="submit">
         | 
| 52 | 
            +
                      </form>
         | 
| 53 | 
            +
                    </body></html>
         | 
| 54 | 
            +
                  '
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
                def post
         | 
| 57 | 
            +
                  Story.new( :title => params['title'], :body => params['body'], :date => Time.now.to_s ).save
         | 
| 58 | 
            +
                  redirect( Index )
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
            end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-dm.yml" )
         | 
    
        data/examples/my_blog.db
    ADDED
    
    | Binary file | 
    
        data/lib/capcode.rb
    CHANGED
    
    | @@ -2,15 +2,18 @@ require 'rubygems' | |
| 2 2 | 
             
            require 'rack'
         | 
| 3 3 | 
             
            require 'json'
         | 
| 4 4 | 
             
            require 'logger'
         | 
| 5 | 
            +
            require 'capcode/version'
         | 
| 5 6 | 
             
            require 'capcode/core_ext'
         | 
| 6 7 |  | 
| 7 8 | 
             
            module Capcode
         | 
| 8 | 
            -
              CAPCOD_VERION="0.2.0"
         | 
| 9 9 | 
             
              @@__ROUTES = {}
         | 
| 10 10 |  | 
| 11 11 | 
             
              class ParameterError < ArgumentError
         | 
| 12 12 | 
             
              end
         | 
| 13 13 |  | 
| 14 | 
            +
              class RouteError < ArgumentError
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
              
         | 
| 14 17 | 
             
              # Helpers contains methods available in your controllers
         | 
| 15 18 | 
             
              module Helpers
         | 
| 16 19 | 
             
                # Help you to return a JSON response
         | 
| @@ -134,9 +137,13 @@ module Capcode | |
| 134 137 | 
             
                      u.each do |_u|
         | 
| 135 138 | 
             
                        m = /\/([^\/]*\(.*)/.match( _u )
         | 
| 136 139 | 
             
                        if m.nil?
         | 
| 140 | 
            +
                          raise Capcode::RouteError, "Route `#{_u}' already defined with regexp `#{h[_u]}' !", caller if h.keys.include?(_u)
         | 
| 137 141 | 
             
                          h[_u] = ''
         | 
| 138 142 | 
             
                        else
         | 
| 139 | 
            -
                           | 
| 143 | 
            +
                          _pre = m.pre_match
         | 
| 144 | 
            +
                          _pre = "/" if _pre.size == 0
         | 
| 145 | 
            +
                          raise Capcode::RouteError, "Route `#{_pre}' already defined with regexp `#{h[_pre]}' !", caller if h.keys.include?(_pre)
         | 
| 146 | 
            +
                          h[_pre] = m.captures[0]
         | 
| 140 147 | 
             
                          max = Regexp.new(m.captures[0]).number_of_captures if max < Regexp.new(m.captures[0]).number_of_captures
         | 
| 141 148 | 
             
                        end
         | 
| 142 149 | 
             
                      end
         | 
| @@ -229,13 +236,18 @@ module Capcode | |
| 229 236 | 
             
                # * <tt>:server</tt> = Server type (webrick or mongrel)
         | 
| 230 237 | 
             
                # * <tt>:log</tt> = Output logfile (default: STDOUT)
         | 
| 231 238 | 
             
                # * <tt>:session</tt> = Session parameters. See Rack::Session for more informations
         | 
| 239 | 
            +
                # * <tt>:pid</tt> = PID file (default: $0.pid)
         | 
| 240 | 
            +
                # * <tt>:daemonize</tt> = Daemonize application (default: false)
         | 
| 232 241 | 
             
                def run( args = {} )
         | 
| 233 242 | 
             
                  conf = {
         | 
| 234 243 | 
             
                    :port => args[:port]||3000, 
         | 
| 235 244 | 
             
                    :host => args[:host]||"localhost",
         | 
| 236 245 | 
             
                    :server => args[:server]||nil,
         | 
| 237 246 | 
             
                    :log => args[:log]||$stdout,
         | 
| 238 | 
            -
                    :session => args[:session]||{}
         | 
| 247 | 
            +
                    :session => args[:session]||{},
         | 
| 248 | 
            +
                    :pid => args[:pid]||"#{$0}.pid",
         | 
| 249 | 
            +
                    :daemonize => args[:daemonize]||false,
         | 
| 250 | 
            +
                    :db_config => args[:db_config]||"database.yml"
         | 
| 239 251 | 
             
                  }
         | 
| 240 252 |  | 
| 241 253 | 
             
                  # Check that mongrel exists 
         | 
| @@ -254,6 +266,7 @@ module Capcode | |
| 254 266 | 
             
                      if eval "Capcode::#{k}.public_methods(true).include?( '__urls__' )"
         | 
| 255 267 | 
             
                        u, m, c = eval "Capcode::#{k}.__urls__"
         | 
| 256 268 | 
             
                        u.keys.each do |_u|
         | 
| 269 | 
            +
                          raise Capcode::RouteError, "Route `#{_u}' already define !", caller if @@__ROUTES.keys.include?(_u)
         | 
| 257 270 | 
             
                          @@__ROUTES[_u] = c.new
         | 
| 258 271 | 
             
                        end
         | 
| 259 272 | 
             
                      end
         | 
| @@ -271,7 +284,31 @@ module Capcode | |
| 271 284 | 
             
            #      app = Rack::Reloader.new(app) ## -- NE RELOAD QUE capcode.rb -- So !!!
         | 
| 272 285 | 
             
                  app = Rack::CommonLogger.new( app, Logger.new(conf[:log]) )
         | 
| 273 286 |  | 
| 287 | 
            +
                  # From rackup !!!
         | 
| 288 | 
            +
                  if conf[:daemonize]
         | 
| 289 | 
            +
                    if RUBY_VERSION < "1.9"
         | 
| 290 | 
            +
                      exit if fork
         | 
| 291 | 
            +
                      Process.setsid
         | 
| 292 | 
            +
                      exit if fork
         | 
| 293 | 
            +
                      # Dir.chdir "/"
         | 
| 294 | 
            +
                      File.umask 0000
         | 
| 295 | 
            +
                      STDIN.reopen "/dev/null"
         | 
| 296 | 
            +
                      STDOUT.reopen "/dev/null", "a"
         | 
| 297 | 
            +
                      STDERR.reopen "/dev/null", "a"
         | 
| 298 | 
            +
                    else
         | 
| 299 | 
            +
                      Process.daemon
         | 
| 300 | 
            +
                    end
         | 
| 301 | 
            +
             | 
| 302 | 
            +
                    File.open(conf[:pid], 'w'){ |f| f.write("#{Process.pid}") }
         | 
| 303 | 
            +
                    at_exit { File.delete(conf[:pid]) if File.exist?(conf[:pid]) }
         | 
| 304 | 
            +
                  end
         | 
| 305 | 
            +
                  
         | 
| 306 | 
            +
                  # Start database
         | 
| 307 | 
            +
                  if self.methods.include? "db_connect"
         | 
| 308 | 
            +
                    db_connect( conf[:db_config], conf[:log] )
         | 
| 309 | 
            +
                  end
         | 
| 274 310 |  | 
| 311 | 
            +
                  # Start server
         | 
| 275 312 | 
             
                  case conf[:server]
         | 
| 276 313 | 
             
                  when "mongrel"
         | 
| 277 314 | 
             
                    puts "** Starting Mongrel on #{conf[:host]}:#{conf[:port]}"
         |