ramaze 2011.07.25 → 2011.10.23

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.
Files changed (181) hide show
  1. data/.gitignore +3 -0
  2. data/.mailmap +3 -2
  3. data/.travis.yml +17 -0
  4. data/.yardopts +13 -0
  5. data/README.md +95 -352
  6. data/examples/app/blog/app.rb +25 -64
  7. data/examples/app/blog/config.ru +11 -9
  8. data/examples/app/blog/controller/init.rb +29 -86
  9. data/examples/app/blog/controller/posts.rb +232 -0
  10. data/examples/app/blog/controller/users.rb +160 -0
  11. data/examples/app/blog/layout/default.xhtml +61 -0
  12. data/examples/app/blog/migrations/01_create_schema.rb +50 -0
  13. data/examples/app/blog/model/comment.rb +41 -54
  14. data/examples/app/blog/model/init.rb +41 -13
  15. data/examples/app/blog/model/post.rb +35 -0
  16. data/examples/app/blog/model/user.rb +105 -0
  17. data/examples/app/blog/public/.htaccess +24 -0
  18. data/examples/app/blog/public/css/grid.css +107 -0
  19. data/examples/app/blog/public/css/layout.css +203 -0
  20. data/examples/app/blog/public/css/reset.css +123 -0
  21. data/examples/app/blog/public/css/text.css +109 -0
  22. data/examples/app/blog/public/dispatch.fcgi +11 -0
  23. data/examples/app/blog/public/favicon.ico +0 -0
  24. data/examples/app/blog/public/images/bg.png +0 -0
  25. data/examples/app/blog/start.rb +18 -3
  26. data/examples/app/blog/view/feed.xhtml +23 -0
  27. data/examples/app/blog/view/form.xhtml +11 -0
  28. data/examples/app/blog/view/index.xhtml +44 -0
  29. data/examples/app/blog/view/users/form.xhtml +12 -0
  30. data/examples/app/blog/view/users/index.xhtml +30 -0
  31. data/examples/app/blog/view/users/login.xhtml +8 -0
  32. data/examples/app/blog/view/view.xhtml +68 -0
  33. data/{doc → guide}/AUTHORS +5 -3
  34. data/{doc → guide}/CHANGELOG +428 -0
  35. data/{doc/GPL → guide/GPL_LICENSE} +0 -0
  36. data/{doc/COPYING → guide/RUBY_LICENSE} +3 -6
  37. data/guide/_static/logo.png +0 -0
  38. data/guide/_static/logo.svg +49 -0
  39. data/guide/_static/ramaze_console.png +0 -0
  40. data/guide/css/common.css +20 -0
  41. data/guide/general/cache.md +167 -0
  42. data/guide/general/configuration.md +168 -0
  43. data/guide/general/contributing.md +108 -0
  44. data/guide/general/controllers.md +115 -0
  45. data/guide/general/helpers.md +76 -0
  46. data/guide/general/installation.md +58 -0
  47. data/guide/general/logging.md +99 -0
  48. data/guide/general/middlewares.md +100 -0
  49. data/guide/general/models.md +78 -0
  50. data/guide/general/principles.md +53 -0
  51. data/guide/general/ramaze_command.md +155 -0
  52. data/guide/general/routes.md +81 -0
  53. data/guide/general/sessions.md +140 -0
  54. data/guide/general/special_thanks.md +67 -0
  55. data/guide/general/testing.md +61 -0
  56. data/guide/general/views.md +322 -0
  57. data/guide/tutorials/introduction.md +259 -0
  58. data/lib/proto/config.ru +1 -1
  59. data/lib/proto/public/favicon.ico +0 -0
  60. data/lib/proto/view/index.xhtml +7 -7
  61. data/lib/ramaze.rb +4 -4
  62. data/lib/ramaze/app.rb +11 -11
  63. data/lib/ramaze/app_graph.rb +2 -4
  64. data/lib/ramaze/bin/console.rb +3 -3
  65. data/lib/ramaze/bin/create.rb +2 -2
  66. data/lib/ramaze/bin/restart.rb +4 -4
  67. data/lib/ramaze/bin/runner.rb +5 -5
  68. data/lib/ramaze/bin/start.rb +19 -4
  69. data/lib/ramaze/bin/status.rb +3 -3
  70. data/lib/ramaze/bin/stop.rb +3 -3
  71. data/lib/ramaze/cache.rb +1 -0
  72. data/lib/ramaze/cache/lru.rb +8 -4
  73. data/lib/ramaze/cache/memcache.rb +32 -13
  74. data/lib/ramaze/cache/redis.rb +164 -0
  75. data/lib/ramaze/cache/sequel.rb +43 -28
  76. data/lib/ramaze/controller.rb +1 -2
  77. data/lib/ramaze/dependencies.rb +40 -3
  78. data/lib/ramaze/helper/bench.rb +26 -16
  79. data/lib/ramaze/helper/blue_form.rb +46 -73
  80. data/lib/ramaze/helper/cache.rb +10 -6
  81. data/lib/ramaze/helper/csrf.rb +35 -39
  82. data/lib/ramaze/helper/disqus.rb +5 -4
  83. data/lib/ramaze/helper/email.rb +35 -24
  84. data/lib/ramaze/helper/erector.rb +9 -13
  85. data/lib/ramaze/helper/flash.rb +7 -9
  86. data/lib/ramaze/helper/formatting.rb +194 -179
  87. data/lib/ramaze/helper/gravatar.rb +4 -8
  88. data/lib/ramaze/helper/identity.rb +3 -3
  89. data/lib/ramaze/helper/layout.rb +23 -8
  90. data/lib/ramaze/helper/markaby.rb +1 -1
  91. data/lib/ramaze/helper/paginate.rb +46 -39
  92. data/lib/ramaze/helper/request_accessor.rb +3 -1
  93. data/lib/ramaze/helper/simple_captcha.rb +18 -17
  94. data/lib/ramaze/helper/stack.rb +1 -1
  95. data/lib/ramaze/helper/tagz.rb +4 -2
  96. data/lib/ramaze/helper/upload.rb +523 -0
  97. data/lib/ramaze/helper/user.rb +4 -8
  98. data/lib/ramaze/helper/xhtml.rb +11 -15
  99. data/lib/ramaze/log.rb +9 -6
  100. data/lib/ramaze/log/rotatinginformer.rb +62 -27
  101. data/lib/ramaze/log/syslog.rb +20 -15
  102. data/lib/ramaze/log/xosd.rb +2 -1
  103. data/lib/ramaze/reloader.rb +2 -0
  104. data/lib/ramaze/request.rb +11 -10
  105. data/lib/ramaze/setup.rb +23 -6
  106. data/lib/ramaze/snippets/array/put_within.rb +3 -9
  107. data/lib/ramaze/snippets/binding/locals.rb +5 -10
  108. data/lib/ramaze/snippets/fiber.rb +1 -23
  109. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +3 -6
  110. data/lib/ramaze/snippets/numeric/filesize_format.rb +3 -5
  111. data/lib/ramaze/snippets/numeric/time.rb +3 -7
  112. data/lib/ramaze/snippets/object/__dir__.rb +3 -7
  113. data/lib/ramaze/snippets/object/instance_variable_defined.rb +3 -6
  114. data/lib/ramaze/snippets/object/pretty.rb +3 -7
  115. data/lib/ramaze/snippets/object/scope.rb +7 -9
  116. data/lib/ramaze/snippets/proc/locals.rb +12 -12
  117. data/lib/ramaze/snippets/ramaze/acquire.rb +15 -14
  118. data/lib/ramaze/snippets/ramaze/deprecated.rb +1 -1
  119. data/lib/ramaze/snippets/ramaze/fiber.rb +1 -1
  120. data/lib/ramaze/snippets/ramaze/lru_hash.rb +2 -3
  121. data/lib/ramaze/snippets/ramaze/struct.rb +2 -4
  122. data/lib/ramaze/snippets/string/camel_case.rb +8 -10
  123. data/lib/ramaze/snippets/string/color.rb +3 -4
  124. data/lib/ramaze/snippets/string/end_with.rb +3 -6
  125. data/lib/ramaze/snippets/string/esc.rb +3 -8
  126. data/lib/ramaze/snippets/string/ord.rb +3 -8
  127. data/lib/ramaze/snippets/string/snake_case.rb +6 -9
  128. data/lib/ramaze/snippets/string/start_with.rb +3 -8
  129. data/lib/ramaze/snippets/string/unindent.rb +3 -6
  130. data/lib/ramaze/snippets/thread/into.rb +1 -3
  131. data/lib/ramaze/spec.rb +2 -31
  132. data/lib/ramaze/spec/bacon.rb +18 -2
  133. data/lib/ramaze/version.rb +1 -1
  134. data/lib/ramaze/view.rb +1 -1
  135. data/ramaze.gemspec +1 -1
  136. data/spec/helper.rb +2 -1
  137. data/spec/ramaze/bin/start.rb +16 -20
  138. data/spec/ramaze/cache/localmemcache.rb +4 -7
  139. data/spec/ramaze/cache/memcache.rb +3 -1
  140. data/spec/ramaze/cache/redis.rb +62 -0
  141. data/spec/ramaze/helper/blue_form.rb +33 -4
  142. data/spec/ramaze/helper/layout.rb +40 -7
  143. data/spec/ramaze/helper/upload.rb +149 -0
  144. data/spec/ramaze/helper/uploads/text_1.txt +1 -0
  145. data/spec/ramaze/helper/uploads/text_2.txt +1 -0
  146. data/spec/ramaze/log/growl.rb +4 -6
  147. data/spec/ramaze/log/syslog.rb +6 -0
  148. data/spec/ramaze/view/lokar.rb +5 -0
  149. data/spec/ramaze/view/nagoro.rb +5 -0
  150. data/tasks/authors.rake +1 -1
  151. data/tasks/bacon.rake +14 -5
  152. data/tasks/changelog.rake +1 -1
  153. data/tasks/yard.rake +12 -4
  154. metadata +277 -239
  155. data/doc/LEGAL +0 -26
  156. data/examples/app/blog/README +0 -3
  157. data/examples/app/blog/controller/comment.rb +0 -45
  158. data/examples/app/blog/controller/entry.rb +0 -85
  159. data/examples/app/blog/controller/main.rb +0 -20
  160. data/examples/app/blog/controller/tag.rb +0 -9
  161. data/examples/app/blog/layout/default.nag +0 -31
  162. data/examples/app/blog/model/entry.rb +0 -89
  163. data/examples/app/blog/model/tag.rb +0 -36
  164. data/examples/app/blog/public/css/screen.css +0 -273
  165. data/examples/app/blog/spec/blog.rb +0 -87
  166. data/examples/app/blog/view/comment/form.nag +0 -10
  167. data/examples/app/blog/view/comment/show.nag +0 -16
  168. data/examples/app/blog/view/entry/edit.nag +0 -14
  169. data/examples/app/blog/view/entry/feed.atom.nag +0 -8
  170. data/examples/app/blog/view/entry/feed.rss.nag +0 -7
  171. data/examples/app/blog/view/entry/index.nag +0 -7
  172. data/examples/app/blog/view/entry/new.nag +0 -13
  173. data/examples/app/blog/view/entry/show.nag +0 -36
  174. data/examples/app/blog/view/feed.atom.nag +0 -18
  175. data/examples/app/blog/view/feed.rss.nag +0 -25
  176. data/examples/app/blog/view/index.nag +0 -6
  177. data/examples/app/blog/view/tag/index.nag +0 -5
  178. data/lib/proto/public/ramaze.png +0 -0
  179. data/lib/ramaze/rest.rb +0 -36
  180. data/spec/ramaze/rest.rb +0 -28
  181. data/tasks/rcov.rake +0 -22
File without changes
@@ -38,15 +38,12 @@ version 2 (see the file GPL), or the conditions below:
38
38
  d) make other distribution arrangements with the author.
39
39
 
40
40
  4. You may modify and include the part of the software into any other
41
- software (possibly commercial). But some files in the distribution
41
+ software (possibly commercial). But some files in the distribution
42
42
  are not written by the author, so that they are not under these terms.
43
43
 
44
- For the list of those files and their copying conditions, see the
45
- file LEGAL.
46
-
47
- 5. The scripts and library files supplied as input to or produced as
44
+ 5. The scripts and library files supplied as input to or produced as
48
45
  output from the software do not automatically fall under the
49
- copyright of the software, but belong to whomever generated them,
46
+ copyright of the software, but belong to whomever generated them,
50
47
  and may be sold commercially, and may be aggregated with this
51
48
  software.
52
49
 
Binary file
@@ -0,0 +1,49 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 43363) -->
3
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <svg version="1.1"
5
+ id="svg2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" sodipodi:docname="ramaze_circle_logo.svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" inkscape:version="0.48.1 r9760"
6
+ xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="300px" height="300px"
7
+ viewBox="-64.75 -65.013 300 300" enable-background="new -64.75 -65.013 300 300" xml:space="preserve">
8
+ <sodipodi:namedview id="base" fit-margin-bottom="0" fit-margin-right="0" fit-margin-left="0" fit-margin-top="0" inkscape:window-y="19" inkscape:window-x="0" showgrid="false" inkscape:current-layer="layer1" inkscape:document-units="px" inkscape:cy="304.76131" inkscape:pageopacity="0.0" borderopacity="1.0" bordercolor="#666666" pagecolor="#ffffff" inkscape:cx="174.2785" inkscape:zoom="0.35355339" inkscape:window-height="747" inkscape:pageshadow="2" inkscape:window-width="1364" inkscape:window-maximized="0">
9
+ </sodipodi:namedview>
10
+ <g id="layer1" transform="translate(-48.0832, -566.213)" inkscape:groupmode="layer" inkscape:label="Layer 1">
11
+ <g id="g3090" transform="matrix(0.382148, 0, 0, 0.382148, 29.7083, 471.954)">
12
+ <path id="path2985-0-2-9" inkscape:connector-curvature="0" fill="#4D4D4D" d="M478.606,340.975L377.809,399.19
13
+ c9.905,17.125,15.573,37.008,15.573,58.215c0,32.151-13.043,61.245-34.115,82.315l82.347,82.344
14
+ C516.135,547.542,531.305,432.248,478.606,340.975z"/>
15
+
16
+ <radialGradient id="path4022_1_" cx="1471.6052" cy="-11840.3555" r="258.7954" gradientTransform="matrix(0.3821 0 0 -0.0439 -299.9709 175.6774)" gradientUnits="userSpaceOnUse">
17
+ <stop offset="0" style="stop-color:#000000"/>
18
+ <stop offset="1" style="stop-color:#000000;stop-opacity:0"/>
19
+ </radialGradient>
20
+
21
+ <path id="path4022" sodipodi:type="arc" sodipodi:cx="148.49242" sodipodi:cy="779.41895" sodipodi:rx="258.80109" sodipodi:ry="29.698484" fill="url(#path4022_1_)" d="
22
+ M521.2,694.912c0,16.404-115.87,29.697-258.801,29.697S3.598,711.316,3.598,694.912c0-16.403,115.87-29.697,258.801-29.697
23
+ S521.2,678.509,521.2,694.912z"/>
24
+ <path id="path2985-0-1" inkscape:connector-curvature="0" fill="#B3B3B3" d="M359.266,539.719
25
+ c-21.067,21.07-50.164,34.113-82.314,34.113v116.429c61.758,0,120.988-24.53,164.661-68.197L359.266,539.719z"/>
26
+ <path id="path2985-3" inkscape:connector-curvature="0" fill="#FF0000" d="M276.952,224.547
27
+ c-128.603,0-232.857,104.254-232.857,232.857c0,128.602,104.254,232.857,232.857,232.857V573.832
28
+ c-64.302,0-116.429-52.126-116.429-116.428s52.128-116.429,116.429-116.429c43.095,0,80.724,23.413,100.856,58.215l100.797-58.215
29
+ C437.011,268.929,360.145,224.547,276.952,224.547z"/>
30
+
31
+ <linearGradient id="path2985-2-4_1_" gradientUnits="userSpaceOnUse" x1="1924.123" y1="-878.1219" x2="1924.123" y2="-1276.0308" gradientTransform="matrix(0.3821 0 0 -0.3821 -458.3633 -76.8066)">
32
+ <stop offset="0" style="stop-color:#000000;stop-opacity:0.4902"/>
33
+ <stop offset="1" style="stop-color:#FFFFFF;stop-opacity:0.4902"/>
34
+ </linearGradient>
35
+ <path id="path2985-2-4" inkscape:connector-curvature="0" fill="url(#path2985-2-4_1_)" d="M276.95,258.097
36
+ c-110.061,0-199.305,89.244-199.305,199.306c0,110.064,89.244,199.277,199.305,199.277c110.063,0,199.28-89.214,199.28-199.277
37
+ C476.229,347.341,387.013,258.097,276.95,258.097z M276.95,340.764c64.418,0,116.641,52.221,116.641,116.639
38
+ S341.368,574.042,276.95,574.042c-64.417,0-116.637-52.221-116.637-116.639S212.533,340.764,276.95,340.764z"/>
39
+ <path id="path2985-0-2" inkscape:connector-curvature="0" fill="#4D4D4D" d="M493.453,332.404l-108.219,62.5
40
+ c10.633,18.385,16.718,39.732,16.718,62.5c0,34.518-14.004,65.753-36.625,88.374l88.406,88.409
41
+ C533.743,554.176,550.029,430.397,493.453,332.404z"/>
42
+ <path id="path2985" inkscape:connector-curvature="0" fill="#FF0000" d="M276.952,207.404c-138.071,0-250,111.929-250,250
43
+ c0,138.073,111.929,250.002,250,250.002V582.403c-69.036,0-125-55.964-125-124.999c0-69.036,55.964-125,125-125
44
+ c46.266,0,86.668,25.137,108.282,62.5l108.219-62.5C448.794,255.054,366.268,207.404,276.952,207.404z"/>
45
+ <path id="path2985-0" inkscape:connector-curvature="0" fill="#B3B3B3" d="M365.328,545.778
46
+ c-22.621,22.621-53.859,36.625-88.375,36.625v125.003c66.304,0,129.896-26.337,176.781-73.219L365.328,545.778z"/>
47
+ </g>
48
+ </g>
49
+ </svg>
@@ -0,0 +1,20 @@
1
+ body
2
+ {
3
+ font-size: 14px;
4
+ line-height: 1.6;
5
+ margin: 0 auto;
6
+ max-width: 960px;
7
+ }
8
+
9
+ code
10
+ {
11
+ background: #f2f2f2;
12
+ padding-left: 3px;
13
+ padding-right: 3px;
14
+ }
15
+
16
+ pre.code
17
+ {
18
+ font-size: 13px;
19
+ line-height: 1.4;
20
+ }
@@ -0,0 +1,167 @@
1
+ # Caching Data
2
+
3
+ Caching data such as API responses, compiled templates or database results can
4
+ give your application a big performance boost. Ramaze tries to make this as easy
5
+ as possible by providing an API that allows you to use different cache
6
+ mechanisms such as Memcache or Sequel using the same syntax.
7
+
8
+ ## Available Drivers
9
+
10
+ * {Ramaze::Cache::Sequel}
11
+ * {Ramaze::Cache::LRU}
12
+ * {Ramaze::Cache::MemCache}
13
+ * {Ramaze::Cache::Redis}
14
+ * {Ramaze::Cache::LocalMemCache}
15
+ * {Innate::Cache::FileBased}
16
+ * {Innate::Cache::DRb}
17
+ * {Innate::Cache::Marshal}
18
+ * {Innate::Cache::Memory}
19
+ * {Innate::Cache::YAML}
20
+
21
+ ## Manually Caching Data
22
+
23
+ Besides making it easy to automatically cache various forms of data Ramaze also
24
+ allows you to manually cache something using your favorite storage engine. In
25
+ order to do this you'll first have to configure Ramaze so that it knows that you
26
+ want to cache something, this can be done as following:
27
+
28
+ Ramaze::Cache.options.names.push(:custom)
29
+ Ramaze::Cache.options.custom = Ramaze::Cache::MemCache
30
+
31
+ # Now we can cache the data
32
+ Ramaze::Cache.custom.store('usernames', ['Pistos', 'Michael Fellinger'])
33
+
34
+ From this point on you can cache your data by calling methods on
35
+ ``Ramaze::Cache.custom``.
36
+
37
+ ## Creating Drivers
38
+
39
+ Odds are there's a cache driver out there that's not supported out of the box.
40
+ Don't worry, adding your own cache driver is pretty easy and I'll try to explain
41
+ it as best as I can.
42
+
43
+ The first step is creating a basic skeleton for our cache class. In it's most
44
+ basic form it looks like the following:
45
+
46
+ # It's not required to declare the cache under the Ramaze namespace, feel free
47
+ # to use a different name.
48
+ module Ramaze
49
+ # Note that Ramaze::Cache is a class, not a module.
50
+ class Cache
51
+ # This is our own custom cache class
52
+ class CustomCache
53
+ # Pre defines the required methods. This ensures all cache drivers can
54
+ # be used in the same way
55
+ include Cache::API
56
+
57
+ end
58
+ end
59
+ end
60
+
61
+ The next step is to override the methods that were created by including
62
+ Ramaze::Cache::API. The first step is adding the method that prepares the cache
63
+ by loading the driver provided by an external Rubygem (e.g. Dalli::Client for
64
+ the Memcache driver) and creating the namespace for the cache. Assuming our gem
65
+ is called "custom-cache" and the class it provides CustomCacheGem our
66
+ cache_setup (that's the name of the setup method) method would look like the
67
+ following:
68
+
69
+ def cache_setup(hostname, username, appname, cachename)
70
+ @namespace = [hostname, username, appname, cachename].compact.join('-')
71
+ @client = CustomCacheGem.new(:namespace => @namespace)
72
+ end
73
+
74
+ The next step is to add the remaining methods so that we can actually use the
75
+ cache.
76
+
77
+ # Removes *all* keys from the cache
78
+ def cache_clear
79
+ @client.delete_all
80
+ end
81
+
82
+ # Removes the specified keys from the cache
83
+ def cache_delete(*keys)
84
+ keys.each do |k|
85
+ @client.delete(k)
86
+ end
87
+ end
88
+
89
+ # Retrieves the specified key or returns the default value
90
+ def cache_fetch(key, default = nil)
91
+ value = @client.get(key)
92
+
93
+ if !value.nil?
94
+ return value
95
+ else
96
+ return default
97
+ end
98
+ end
99
+
100
+ # Stores the data in the cache and return the value
101
+ def cache_store(key, value)
102
+ @client.set(key, value)
103
+ return value
104
+ end
105
+
106
+ Depending on the API of your cache mechanism the method names and the way
107
+ they're used may vary.
108
+
109
+ The entire cache class now looks like the following:
110
+
111
+ # It's not required to declare the cache under the Ramaze namespace, feel free
112
+ # to use a different name.
113
+ module Ramaze
114
+ # Note that Ramaze::Cache is a class, not a module.
115
+ class Cache
116
+ # This is our own custom cache class
117
+ class CustomCache
118
+ # Pre defines the required methods. This ensures all cache drivers can
119
+ # be used in the same way
120
+ include Cache::API
121
+
122
+ # Prepares the cache
123
+ def cache_setup(hostname, username, appname, cachename)
124
+ @namespace = [hostname, username, appname, cachename].compact.join('-')
125
+ @client = CustomCacheGem.new(:namespace => @namespace)
126
+ end
127
+
128
+ # Removes *all* keys from the cache
129
+ def cache_clear
130
+ @client.delete_all
131
+ end
132
+
133
+ # Removes the specified keys from the cache
134
+ def cache_delete(*keys)
135
+ keys.each do |k|
136
+ @client.delete(k)
137
+ end
138
+ end
139
+
140
+ # Retrieves the specified key or returns the default value
141
+ def cache_fetch(key, default = nil)
142
+ value = @client.get(key)
143
+
144
+ if !value.nil?
145
+ return value
146
+ else
147
+ return default
148
+ end
149
+ end
150
+
151
+ # Stores the data in the cache and return the value
152
+ def cache_store(key, value)
153
+ @client.set(key, value)
154
+ return value
155
+ end
156
+ end # CustomCache
157
+ end # Cache
158
+ end # Ramaze
159
+
160
+ There really isn't that much to it when it comes to creating a cache driver. The
161
+ important thing to remember is that the following methods are always required:
162
+
163
+ * cache_setup
164
+ * cache_clear
165
+ * cache_delete
166
+ * cache_fetch
167
+ * cache_store
@@ -0,0 +1,168 @@
1
+ # Configuration
2
+
3
+ Ramaze provides two ways of setting configuration options, using
4
+ ``Ramaze::Optioned`` and ``Ramaze::Traited``.
5
+
6
+ Both Ramaze::Optioned and Ramaze::Traited are aliases for Innate::Optioned and
7
+ Innate::Traited respectively.
8
+
9
+ ## Traits using Ramaze::Traited
10
+
11
+ Traits provide a way of setting configuration options in a class similar to
12
+ class variables. The advantage of using traits is that they are inherited in
13
+ classes which allows you to use different values for a trait in a parent and
14
+ child class. On top of that you can access traits outside of a class' scope
15
+ (class variables are private). Ramaze uses traits for various configuration
16
+ settings that are specific to a certain class' instance or module.
17
+ ``Ramaze::Optioned`` can't be used for this since the options set would be the
18
+ same for all instances whereas traits can have their own values.
19
+
20
+ Using traits is quite simple and can be done by including the module
21
+ Ramaze::Traited into your class:
22
+
23
+ class Something
24
+ include Ramaze::Traited
25
+ end
26
+
27
+ This module can be included into controllers, models or any other class. Once
28
+ this module has been included into a class you can define a trait using the
29
+ method ``trait()``. This method takes a hash where the key is the name of the
30
+ trait and the value the value for that trait:
31
+
32
+ class Something
33
+ include Ramaze::Traited
34
+
35
+ trait :language => 'ruby'
36
+ end
37
+
38
+ Inside a class instance traits can also be retrieved using this method by simply
39
+ specifying the name of the trait:
40
+
41
+ class Something
42
+ include Ramaze::Traited
43
+
44
+ trait :language => 'ruby'
45
+
46
+ def language
47
+ puts "Language: #{trait[:language]}"
48
+ end
49
+ end
50
+
51
+ Outside of a class' instance you can still retrieve a trait but you need to call
52
+ ``class_trait()`` instead:
53
+
54
+ Something.class_trait[:language] # => "ruby"
55
+
56
+ Another cool feature of ``Ramaze::Traited`` is that you can get a list of all
57
+ traits of a class and all it's parent classes using ``ancestral_trait()``. This
58
+ method retrieves all traits where each trait that's redefined will overwrite the
59
+ existing one. Example:
60
+
61
+ class Foo
62
+ include Ramaze::Traited
63
+ trait :one => :eins, :first => :erstes
64
+ end
65
+
66
+ class Bar < Foo
67
+ trait :two => :zwei
68
+ end
69
+
70
+ class Foobar < Bar
71
+ trait :three => :drei, :first => :overwritten
72
+ end
73
+
74
+ Foobar.ancestral_trait
75
+ # => {:three => :drei, :two => :zwei, :one => :eins, :first => :overwritten}
76
+
77
+ ## Options using Ramaze::Optioned
78
+
79
+ Ramaze::Optioned can be used to set global options regardless of the instance of
80
+ a class. Options set using this module are also inherited but you can't set
81
+ different values for different instances. A good use case for Ramaze::Optioned
82
+ is the helper ``Ramaze::Helper::Email``. This helper specifies certain options
83
+ such as the SMTP host and username. These options don't change in a request or
84
+ in an instance of a controller so using traits would be useless. It's also quite
85
+ rare that you want to use different settings in a sub controller.
86
+
87
+ Settings options using Ramaze::Optioned works a bit different compared to traits
88
+ but don't worry, it's very easy. First you must include the module and then call
89
+ ``options.dsl()`` as shown below.
90
+
91
+ class Something
92
+ include Ramaze::Optioned
93
+
94
+ options.dsl do
95
+
96
+ end
97
+ end
98
+
99
+ Inside the block passed to ``options.dsl()`` you can call the ``option`` method
100
+ (aliased as ``o`` so you have to write less code). This method has the following
101
+ syntax:
102
+
103
+ option(description, name, default value)
104
+
105
+ Say we want to define a option that allows the user to change a username, this
106
+ can be done as following:
107
+
108
+ class Something
109
+ include Ramaze::Optioned
110
+
111
+ options.dsl do
112
+ o 'Defines the username', :username, 'ramaze'
113
+ end
114
+ end
115
+
116
+ Once an option is set it can be retrieved by calling ``options`` on the class
117
+ (regardless of whether or not the call was made inside an instance):
118
+
119
+ # Outside of the class
120
+ Something.options.username # => "ramaze"
121
+
122
+ # Inside the class
123
+ options.username # => "ramaze"
124
+
125
+ Dumping the entire options object to the command line using ``puts`` (or
126
+ something similar) will also show the description of each option, the default
127
+ value, etc:
128
+
129
+ Something.options # => {:username=>{:doc=>"Defines the username", :value=>"ramaze"}}
130
+
131
+ ## Configuring Paths
132
+
133
+ While Ramaze is a very flexible framework it requires some basic information
134
+ about the location of your views, layouts and so on. Ramaze does not
135
+ automatically tries to locate these but instead uses a set of defined locations
136
+ to look for. These paths are set using ``Ramaze::Optioned`` and can be found in
137
+ the following options:
138
+
139
+ * Ramaze.options.views
140
+ * Ramaze.options.publics
141
+ * Ramaze.options.layouts
142
+ * Ramaze.options.roots
143
+
144
+ Helpers aren't defined in these paths as they're considered a separate part of
145
+ Ramaze. Instead of using ``Ramaze.options`` you'll have to update
146
+ ``Ramaze::HelpersHelper.options.paths``.
147
+
148
+ Note that ``Ramaze.options.roots`` and ``Ramaze::HelpersHelper.options.paths``
149
+ are the only two options that use absolute paths, all other paths are relative
150
+ to the root directories.
151
+
152
+ Let's say you want to have an extra view directory called "templates", this
153
+ directory can be added as following:
154
+
155
+ Ramaze.options.views.push('templates')
156
+
157
+ If the "templates" directory is located a level above the application root you'd
158
+ do the following instead:
159
+
160
+ Ramaze.options.views.push('../templates')
161
+
162
+ As mentioned before the root directories are absolute, this means that if you
163
+ want to add a root directory you have to specify the full path to it:
164
+
165
+ Ramaze.options.roots.push('/path/to/another/root/directory')
166
+
167
+ Technically you can specify relative paths but this might lead to unexpected
168
+ behavior so it's not recommended.
@@ -0,0 +1,108 @@
1
+ # Contributing To Ramaze
2
+
3
+ Everybody is welcome to contribute to Ramaze and/or the guide. This guide is
4
+ meant to be a starting point for those interested in contributing code, writing
5
+ documentation or advertising Ramaze.
6
+
7
+ ## Coding Standards
8
+
9
+ * 2 spaces per indentation level for Ruby code.
10
+ * Document your code as much as you can.
11
+ * Write Bacon specifications for each change you make, especially when adding
12
+ new features.
13
+ * Use Markdown for markup, both when documenting source code as well as when
14
+ writing pages for the guide.
15
+ * Code should be hard wrapped at 80 characters.
16
+ * Variables and methods are ``lower_cased`` while constants such as those used
17
+ to store version numbers use ``SCREAMING_SNAKE_CASE``. An example of this is
18
+ ``Ramaze::VERSION``. Class names and the like are ``PascalCased``.
19
+
20
+ ## Git Usage and Standards
21
+
22
+ Ramaze uses [Git][git] as it's version control system. In order to contribute to
23
+ Ramaze using Git there are a few things to keep in mind and a few standards to
24
+ follow.
25
+
26
+ ### Commit Messages
27
+
28
+ Commit messages should be splitted up in two parts, a short description of the
29
+ commit in 50 characters or less. This short description should be followed by an
30
+ empty line which in turn is followed by a long description. The short
31
+ description can be seen as an Email subject while the long description would be
32
+ the actual Email body. An example of such a commit message is the following:
33
+
34
+ Moved some chapters around.
35
+
36
+ The chapters on helpers and logging data have been moved to their own file
37
+ instead of being displayed in the README. Next up is writing the actual
38
+ documentation on logging data.
39
+
40
+ Signed-off-by: Yorick Peterse <yorickpeterse@gmail.com>
41
+
42
+ Each commit should only contain a related set of changes. If you're adding a
43
+ feature but found a bug and fixed it it's easier to keep track of changes if the
44
+ bug and the feature are divided into two separate commits (if possible). This
45
+ makes it easier to revert certain changes when needed or pick specific commits
46
+ from a branch (using ``git cherry-pick``).
47
+
48
+ ### Branching
49
+
50
+ When working on code your changes should be made in a separate branch. The name
51
+ of this branch should be related to the changes you're making and should be
52
+ short. For example, if you're working on a chapter for the guide you could name
53
+ it "documentation". Or maybe you're working on a helper, in that case you could
54
+ name it "example-helper". In the end it doesn't really matter, just keep the
55
+ length down a bit. Putting your changes in a separate branch makes it easier to
56
+ manage them and pull them into the main (master) branch.
57
+
58
+ ### Pull Requests
59
+
60
+ Once you've finished working on your changes you should notify us about the
61
+ changes. The easiest way to do this is to send a pull request on Github.
62
+ Information about sending and handling pull requests can be found on the [Pull
63
+ request][pull requests] page on Github.
64
+
65
+ ## Writing Documentation
66
+
67
+ The documentation (both the guides and the API documentation) use
68
+ [Markdown][markdown] as its markup engine. All the text should be written in
69
+ English. Try writing as clear as possible and remove as much spelling/grammar
70
+ errors as you can find before submitting it to Ramaze.
71
+
72
+ Linking to classes and methods can be done by wrapping the namespace/method in
73
+ ``{}``:
74
+
75
+ {Ramaze::VERSION}
76
+
77
+ If you want to link to an internal file you should use the following syntax
78
+ instead:
79
+
80
+ {file:path/to/file Title}
81
+
82
+ Markdown files should be lower cased, spaces should be replaced with
83
+ underscores. Examples of this are ``ramaze_command.md`` and
84
+ ``special_thanks.md``. Just like the Ruby code the text for the guide should be
85
+ wrapped at 80 characters.
86
+
87
+ ## Spreading The Word
88
+
89
+ Maybe you're not familiar with Git or perhaps you just don't have the time to
90
+ contribute code. In both cases there are things you can do to help Ramaze grow.
91
+ The easiest way is to just tell people about it. Talk to co-workers, give
92
+ presentations or just suggest it whenever you think it could be useful for
93
+ people.
94
+
95
+ If you like to use the Ramaze logo for a presentation or something else you can
96
+ freely use the official Ramaze logo displayed below. The logo is licensed under
97
+ a [Creative Commons][cc license] license. The logo comes in two formats, a SVG
98
+ file and a PNG of which both are displayed below.
99
+
100
+ ![Logo SVG][logo svg]
101
+ ![Logo PNG][logo png]
102
+
103
+ [git]: http://git-scm.com/
104
+ [pull requests]: http://help.github.com/send-pull-requests/
105
+ [markdown]: http://daringfireball.net/projects/markdown/
106
+ [cc license]: http://creativecommons.org/licenses/by-sa/3.0/
107
+ [logo svg]: _static/logo.svg "The logo in SVG format"
108
+ [logo png]: _static/logo.png "The logo in PNG format"