middleman-core-x86-mingw32 3.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (401) hide show
  1. data/.cane +2 -0
  2. data/.cane-exclusions.yml +5 -0
  3. data/.gemtest +0 -0
  4. data/Rakefile +7 -0
  5. data/bin/middleman +25 -0
  6. data/features/3rd_party_cli.feature +15 -0
  7. data/features/auto_layout.feature +36 -0
  8. data/features/automatic_directory_matcher.feature +32 -0
  9. data/features/builder.feature +50 -0
  10. data/features/chained_templates.feature +19 -0
  11. data/features/clean_build.feature +28 -0
  12. data/features/cli_extension.feature +14 -0
  13. data/features/cli_init.feature +89 -0
  14. data/features/current_page_request_path_backwards.feature +6 -0
  15. data/features/custom_layout_engines.feature +8 -0
  16. data/features/custom_layouts.feature +64 -0
  17. data/features/data.feature +22 -0
  18. data/features/dynamic_pages.feature +133 -0
  19. data/features/extensionless_text_files.feature +24 -0
  20. data/features/feature_params.feature +6 -0
  21. data/features/front-matter.feature +72 -0
  22. data/features/frontmatter_page_settings.feature +43 -0
  23. data/features/helpers_external.feature +12 -0
  24. data/features/ignore.feature +121 -0
  25. data/features/implied_extensions.feature +69 -0
  26. data/features/instance_vars.feature +9 -0
  27. data/features/mount_rack.feature +8 -0
  28. data/features/preview_changes.feature +29 -0
  29. data/features/request_params.feature +6 -0
  30. data/features/sitemap_traversal.feature +73 -0
  31. data/features/static_server.feature +6 -0
  32. data/features/step_definitions/page_layout_steps.rb +15 -0
  33. data/features/strip_url.feature +40 -0
  34. data/features/support/env.rb +6 -0
  35. data/features/unicode_filenames.feature +36 -0
  36. data/features/wildcard_page_helper.feature +10 -0
  37. data/fixtures/automatic-directory-matcher-app/config.rb +1 -0
  38. data/fixtures/automatic-directory-matcher-app/source/root-plain.html +1 -0
  39. data/fixtures/automatic-directory-matcher-app/source/root.html.erb +1 -0
  40. data/fixtures/automatic-directory-matcher-app/source/sub--sub--sub-plain.html +1 -0
  41. data/fixtures/automatic-directory-matcher-app/source/sub--sub--sub.html.erb +1 -0
  42. data/fixtures/automatic-directory-matcher-app/source/sub--sub-plain.html +1 -0
  43. data/fixtures/automatic-directory-matcher-app/source/sub--sub.html.erb +1 -0
  44. data/fixtures/basic-data-app/config.rb +4 -0
  45. data/fixtures/basic-data-app/data/test.yml +4 -0
  46. data/fixtures/basic-data-app/data/test2.json +4 -0
  47. data/fixtures/basic-data-app/source/data.html.erb +1 -0
  48. data/fixtures/basic-data-app/source/data3.html.erb +1 -0
  49. data/fixtures/build-with-errors-app/config.rb +1 -0
  50. data/fixtures/build-with-errors-app/source/index.html.erb +1 -0
  51. data/fixtures/chained-app/config.rb +0 -0
  52. data/fixtures/chained-app/data/article.yml +2 -0
  53. data/fixtures/chained-app/source/index.html.str.erb +8 -0
  54. data/fixtures/clean-app/config-complications.rb +11 -0
  55. data/fixtures/clean-app/config-empty.rb +0 -0
  56. data/fixtures/clean-app/config.rb +11 -0
  57. data/fixtures/clean-app/source/index.html.erb +1 -0
  58. data/fixtures/clean-app/source/layout.erb +9 -0
  59. data/fixtures/clean-app/source/layouts/custom.erb +8 -0
  60. data/fixtures/clean-app/source/real/index.html.erb +5 -0
  61. data/fixtures/clean-app/source/real.html +1 -0
  62. data/fixtures/clean-app/source/should_be_ignored.html +1 -0
  63. data/fixtures/clean-app/source/should_be_ignored2.html +1 -0
  64. data/fixtures/clean-app/source/should_be_ignored3.html +1 -0
  65. data/fixtures/clean-app/source/static.html +1 -0
  66. data/fixtures/clean-nested-app/config.rb +3 -0
  67. data/fixtures/clean-nested-app/source/about.html +1 -0
  68. data/fixtures/csspie/config.rb +0 -0
  69. data/fixtures/csspie/source/stylesheets/PIE.htc +96 -0
  70. data/fixtures/current-page-app/config.rb +3 -0
  71. data/fixtures/current-page-app/source/request-path.html.erb +1 -0
  72. data/fixtures/custom-layout-app/config.rb +1 -0
  73. data/fixtures/custom-layout-app/source/index.html.erb +1 -0
  74. data/fixtures/custom-layout-app/source/layout.str +9 -0
  75. data/fixtures/custom-layout-app2/config.rb +0 -0
  76. data/fixtures/custom-layout-app2/source/custom-layout-dir/index.html.erb +1 -0
  77. data/fixtures/custom-layout-app2/source/custom-layout.html.erb +1 -0
  78. data/fixtures/custom-layout-app2/source/layouts/custom.erb +8 -0
  79. data/fixtures/data-app/config.rb +3 -0
  80. data/fixtures/data-app/data/pages.yml +6 -0
  81. data/fixtures/data-app/source/index.html.erb +1 -0
  82. data/fixtures/data-app/source/layout.erb +5 -0
  83. data/fixtures/different-engine-layout/config.rb +0 -0
  84. data/fixtures/different-engine-layout/source/index.html.str +1 -0
  85. data/fixtures/different-engine-layout/source/layout.erb +9 -0
  86. data/fixtures/dynamic-pages-app/config.rb +52 -0
  87. data/fixtures/dynamic-pages-app/source/real/index.html.erb +9 -0
  88. data/fixtures/dynamic-pages-app/source/real.html +1 -0
  89. data/fixtures/dynamic-pages-app/source/should_be_ignored.html +1 -0
  90. data/fixtures/dynamic-pages-app/source/should_be_ignored2.html +1 -0
  91. data/fixtures/dynamic-pages-app/source/should_be_ignored3.html +1 -0
  92. data/fixtures/dynamic-pages-app/source/should_be_ignored4.html +1 -0
  93. data/fixtures/dynamic-pages-app/source/should_be_ignored5.html +1 -0
  94. data/fixtures/dynamic-pages-app/source/should_be_ignored6.html +1 -0
  95. data/fixtures/dynamic-pages-app/source/should_be_ignored7.html +1 -0
  96. data/fixtures/dynamic-pages-app/source/should_be_ignored8.html +1 -0
  97. data/fixtures/empty-app/not-config.rb +0 -0
  98. data/fixtures/engine-matching-layout/config.rb +0 -0
  99. data/fixtures/engine-matching-layout/source/index.html.erb +1 -0
  100. data/fixtures/engine-matching-layout/source/layout.erb +9 -0
  101. data/fixtures/extensionless-text-files-app/config.rb +0 -0
  102. data/fixtures/extensionless-text-files-app/source/CNAME +1 -0
  103. data/fixtures/extensionless-text-files-app/source/LICENSE +1 -0
  104. data/fixtures/extensionless-text-files-app/source/README +1 -0
  105. data/fixtures/extensionless-text-files-app/source/index.html +1 -0
  106. data/fixtures/external-helpers/config.rb +4 -0
  107. data/fixtures/external-helpers/helpers/derp.rb +3 -0
  108. data/fixtures/external-helpers/helpers/four_helpers.rb +3 -0
  109. data/fixtures/external-helpers/helpers/one_helper.rb +3 -0
  110. data/fixtures/external-helpers/helpers/yet_another_thingy.rb +3 -0
  111. data/fixtures/external-helpers/lib/hello_helper.rb +5 -0
  112. data/fixtures/external-helpers/source/automatic.html.erb +1 -0
  113. data/fixtures/external-helpers/source/index.html.erb +1 -0
  114. data/fixtures/feature-params-app/config.rb +12 -0
  115. data/fixtures/feature-params-app/source/index.html.erb +3 -0
  116. data/fixtures/frontmatter-app/config.rb +0 -0
  117. data/fixtures/frontmatter-app/source/front-matter-2.php.erb +7 -0
  118. data/fixtures/frontmatter-app/source/front-matter-auto.erb +6 -0
  119. data/fixtures/frontmatter-app/source/front-matter-change.html.erb +5 -0
  120. data/fixtures/frontmatter-app/source/front-matter-encoding.html.erb +7 -0
  121. data/fixtures/frontmatter-app/source/front-matter-line-2.html.erb +7 -0
  122. data/fixtures/frontmatter-app/source/json-front-matter-2.php.erb +7 -0
  123. data/fixtures/frontmatter-app/source/json-front-matter-auto.erb +6 -0
  124. data/fixtures/frontmatter-app/source/json-front-matter-encoding.html.erb +7 -0
  125. data/fixtures/frontmatter-app/source/json-front-matter-line-2.html.erb +7 -0
  126. data/fixtures/frontmatter-app/source/json-front-matter.html.erb +6 -0
  127. data/fixtures/frontmatter-settings-app/config.rb +4 -0
  128. data/fixtures/frontmatter-settings-app/source/alternate_layout.html.erb +5 -0
  129. data/fixtures/frontmatter-settings-app/source/ignored.html.erb +5 -0
  130. data/fixtures/frontmatter-settings-app/source/layouts/alternate.erb +3 -0
  131. data/fixtures/frontmatter-settings-app/source/layouts/override.erb +2 -0
  132. data/fixtures/frontmatter-settings-app/source/override_layout.html.erb +4 -0
  133. data/fixtures/frontmatter-settings-app/source/page_mentioned.html.erb +4 -0
  134. data/fixtures/generator-test/config.rb +80 -0
  135. data/fixtures/generator-test/source/index.html.erb +10 -0
  136. data/fixtures/glob-app/config.rb +1 -0
  137. data/fixtures/glob-app/source/index.html.erb +4 -0
  138. data/fixtures/glob-app/source/stylesheets/site.css.str +3 -0
  139. data/fixtures/ignore-app/source/about.html.erb +1 -0
  140. data/fixtures/ignore-app/source/images/icon/messages.png +0 -0
  141. data/fixtures/ignore-app/source/images/pic.png +0 -0
  142. data/fixtures/ignore-app/source/images/portrait.jpg +0 -0
  143. data/fixtures/ignore-app/source/index.html.erb +0 -0
  144. data/fixtures/ignore-app/source/plain.html +1 -0
  145. data/fixtures/ignore-app/source/reports/another.html +0 -0
  146. data/fixtures/ignore-app/source/reports/index.html +0 -0
  147. data/fixtures/implied-extensions-app/config.rb +0 -0
  148. data/fixtures/implied-extensions-app/source/index.erb +1 -0
  149. data/fixtures/indexable-app/config.rb +0 -0
  150. data/fixtures/indexable-app/source/.htaccess +1 -0
  151. data/fixtures/indexable-app/source/a_folder/needs_index.html +1 -0
  152. data/fixtures/indexable-app/source/leave_me_alone.html +1 -0
  153. data/fixtures/indexable-app/source/needs_index.html +1 -0
  154. data/fixtures/indexable-app/source/regular/index.html +1 -0
  155. data/fixtures/indexable-app/source/wildcard_leave_me_alone.html +1 -0
  156. data/fixtures/instance-vars-app/config.rb +7 -0
  157. data/fixtures/instance-vars-app/source/content.html.erb +2 -0
  158. data/fixtures/instance-vars-app/source/layout.erb +1 -0
  159. data/fixtures/large-build-app/config.rb +3 -0
  160. data/fixtures/large-build-app/source/.htaccess +1 -0
  161. data/fixtures/large-build-app/source/_partial.erb +1 -0
  162. data/fixtures/large-build-app/source/feed.xml.builder +4 -0
  163. data/fixtures/large-build-app/source/images/Child folder/regular_file(example).txt +1 -0
  164. data/fixtures/large-build-app/source/images/Read me (example).txt +1 -0
  165. data/fixtures/large-build-app/source/images/blank.gif +0 -0
  166. data/fixtures/large-build-app/source/index.html.erb +1 -0
  167. data/fixtures/large-build-app/source/layout.erb +9 -0
  168. data/fixtures/large-build-app/source/layouts/content_for.erb +4 -0
  169. data/fixtures/large-build-app/source/layouts/custom.erb +8 -0
  170. data/fixtures/large-build-app/source/other_layout.erb +1 -0
  171. data/fixtures/large-build-app/source/services/index.html.erb +1 -0
  172. data/fixtures/large-build-app/source/spaces in file.html.erb +1 -0
  173. data/fixtures/large-build-app/source/static.html +1 -0
  174. data/fixtures/large-build-app/source/stylesheets/static.css +2 -0
  175. data/fixtures/manual-layout/config.rb +1 -0
  176. data/fixtures/manual-layout/source/index.html.erb +1 -0
  177. data/fixtures/manual-layout/source/layouts/custom.erb +9 -0
  178. data/fixtures/manual-layout-missing/config.rb +1 -0
  179. data/fixtures/manual-layout-missing/source/index.html.erb +1 -0
  180. data/fixtures/manual-layout-override/config.rb +3 -0
  181. data/fixtures/manual-layout-override/source/index.html.erb +1 -0
  182. data/fixtures/manual-layout-override/source/layouts/another.erb +9 -0
  183. data/fixtures/manual-layout-override/source/layouts/custom.erb +9 -0
  184. data/fixtures/multiple-layouts/config.rb +0 -0
  185. data/fixtures/multiple-layouts/source/index.html.erb +1 -0
  186. data/fixtures/multiple-layouts/source/layout.erb +9 -0
  187. data/fixtures/multiple-layouts/source/layout.str +9 -0
  188. data/fixtures/no-layout/config.rb +0 -0
  189. data/fixtures/no-layout/source/index.html.erb +1 -0
  190. data/fixtures/page-helper-layout-block-app/config.rb +6 -0
  191. data/fixtures/page-helper-layout-block-app/source/index.html.erb +1 -0
  192. data/fixtures/page-helper-layout-block-app/source/layouts/alt.erb +3 -0
  193. data/fixtures/page-helper-layout-block-app/source/layouts/layout.erb +3 -0
  194. data/fixtures/page-helper-layout-block-app/source/path/child.html.erb +1 -0
  195. data/fixtures/page-helper-layout-block-app/source/path/index.html.erb +1 -0
  196. data/fixtures/plain-app/index.html +1 -0
  197. data/fixtures/preview-app/config.rb +0 -0
  198. data/fixtures/preview-app/source/content.html.erb +1 -0
  199. data/fixtures/preview-app/source/layout.erb +1 -0
  200. data/fixtures/request-app/config.rb +0 -0
  201. data/fixtures/request-app/source/index.html.erb +3 -0
  202. data/fixtures/sinatra-app/config.rb +11 -0
  203. data/fixtures/sinatra-app/source/index.html.erb +5 -0
  204. data/fixtures/strip-url-app/config.rb +0 -0
  205. data/fixtures/strip-url-app/source/index.html.erb +1 -0
  206. data/fixtures/strip-url-app/source/other.html.erb +1 -0
  207. data/fixtures/strip-url-app/source/subdir/index.html.erb +1 -0
  208. data/fixtures/traversal-app/config.rb +5 -0
  209. data/fixtures/traversal-app/source/directory-indexed/sibling.html.erb +3 -0
  210. data/fixtures/traversal-app/source/directory-indexed/sibling2.html.erb +3 -0
  211. data/fixtures/traversal-app/source/directory-indexed/sub2/index.html.erb +0 -0
  212. data/fixtures/traversal-app/source/directory-indexed/sub3/deep.html.erb +0 -0
  213. data/fixtures/traversal-app/source/directory-indexed.html.erb +0 -0
  214. data/fixtures/traversal-app/source/index.html.erb +0 -0
  215. data/fixtures/traversal-app/source/layout.erb +21 -0
  216. data/fixtures/traversal-app/source/proxied.html.erb +0 -0
  217. data/fixtures/traversal-app/source/root.html.erb +0 -0
  218. data/fixtures/traversal-app/source/sub/index.html.erb +0 -0
  219. data/fixtures/traversal-app/source/sub/sibling.html.erb +0 -0
  220. data/fixtures/traversal-app/source/sub/sibling2.html.erb +0 -0
  221. data/fixtures/traversal-app/source/sub/sub2/index.html.erb +0 -0
  222. data/fixtures/traversal-app/source/sub/sub3/deep.html.erb +0 -0
  223. data/fixtures/wildcard-app/config.rb +1 -0
  224. data/fixtures/wildcard-app/source/admin/index.html.erb +1 -0
  225. data/fixtures/wildcard-app/source/admin/page.html.erb +1 -0
  226. data/fixtures/wildcard-app/source/index.html.erb +1 -0
  227. data/fixtures/wildcard-app/source/layouts/admin.erb +2 -0
  228. data/fixtures/wildcard-app/source/layouts/layout.erb +2 -0
  229. data/lib/middleman/rack.rb +4 -0
  230. data/lib/middleman-core/application.rb +245 -0
  231. data/lib/middleman-core/cli/build.rb +286 -0
  232. data/lib/middleman-core/cli/bundler.rb +40 -0
  233. data/lib/middleman-core/cli/extension.rb +49 -0
  234. data/lib/middleman-core/cli/init.rb +58 -0
  235. data/lib/middleman-core/cli/server.rb +73 -0
  236. data/lib/middleman-core/cli.rb +89 -0
  237. data/lib/middleman-core/core_extensions/builder.rb +17 -0
  238. data/lib/middleman-core/core_extensions/data.rb +180 -0
  239. data/lib/middleman-core/core_extensions/extensions.rb +161 -0
  240. data/lib/middleman-core/core_extensions/external_helpers.rb +39 -0
  241. data/lib/middleman-core/core_extensions/file_watcher.rb +167 -0
  242. data/lib/middleman-core/core_extensions/front_matter.rb +213 -0
  243. data/lib/middleman-core/core_extensions/rendering.rb +439 -0
  244. data/lib/middleman-core/core_extensions/request.rb +338 -0
  245. data/lib/middleman-core/core_extensions/routing.rb +94 -0
  246. data/lib/middleman-core/core_extensions/ruby_encoding.rb +24 -0
  247. data/lib/middleman-core/core_extensions/show_exceptions.rb +31 -0
  248. data/lib/middleman-core/core_extensions.rb +33 -0
  249. data/lib/middleman-core/extensions.rb +103 -0
  250. data/lib/middleman-core/load_paths.rb +56 -0
  251. data/lib/middleman-core/logger.rb +29 -0
  252. data/lib/middleman-core/preview_server.rb +186 -0
  253. data/lib/middleman-core/profiling.rb +58 -0
  254. data/lib/middleman-core/renderers/coffee_script.rb +45 -0
  255. data/lib/middleman-core/renderers/erb.rb +36 -0
  256. data/lib/middleman-core/renderers/haml.rb +30 -0
  257. data/lib/middleman-core/renderers/less.rb +49 -0
  258. data/lib/middleman-core/renderers/liquid.rb +35 -0
  259. data/lib/middleman-core/renderers/markdown.rb +56 -0
  260. data/lib/middleman-core/renderers/redcarpet.rb +58 -0
  261. data/lib/middleman-core/renderers/sass.rb +101 -0
  262. data/lib/middleman-core/renderers/slim.rb +38 -0
  263. data/lib/middleman-core/sitemap/extensions/ignores.rb +91 -0
  264. data/lib/middleman-core/sitemap/extensions/on_disk.rb +84 -0
  265. data/lib/middleman-core/sitemap/extensions/proxies.rb +114 -0
  266. data/lib/middleman-core/sitemap/extensions/traversal.rb +84 -0
  267. data/lib/middleman-core/sitemap/resource.rb +149 -0
  268. data/lib/middleman-core/sitemap/store.rb +219 -0
  269. data/lib/middleman-core/sitemap.rb +78 -0
  270. data/lib/middleman-core/step_definitions/builder_steps.rb +56 -0
  271. data/lib/middleman-core/step_definitions/middleman_steps.rb +17 -0
  272. data/lib/middleman-core/step_definitions/server_steps.rb +91 -0
  273. data/lib/middleman-core/step_definitions.rb +12 -0
  274. data/lib/middleman-core/templates/default/source/images/background.png +0 -0
  275. data/lib/middleman-core/templates/default/source/images/middleman.png +0 -0
  276. data/lib/middleman-core/templates/default/source/index.html.erb +10 -0
  277. data/lib/middleman-core/templates/default/source/javascripts/all.js +1 -0
  278. data/lib/middleman-core/templates/default/source/layouts/layout.erb +19 -0
  279. data/lib/middleman-core/templates/default/source/stylesheets/all.css +55 -0
  280. data/lib/middleman-core/templates/default/source/stylesheets/normalize.css +431 -0
  281. data/lib/middleman-core/templates/default.rb +38 -0
  282. data/lib/middleman-core/templates/extension/Gemfile +17 -0
  283. data/lib/middleman-core/templates/extension/Rakefile +14 -0
  284. data/lib/middleman-core/templates/extension/features/support/env.rb +4 -0
  285. data/lib/middleman-core/templates/extension/gemspec +24 -0
  286. data/lib/middleman-core/templates/extension/gitignore +2 -0
  287. data/lib/middleman-core/templates/extension/lib/lib.rb +49 -0
  288. data/lib/middleman-core/templates/extension/lib/middleman_extension.rb +1 -0
  289. data/lib/middleman-core/templates/html5/source/404.html +43 -0
  290. data/lib/middleman-core/templates/html5/source/README.md +55 -0
  291. data/lib/middleman-core/templates/html5/source/apple-touch-icon-114x114-precomposed.png +0 -0
  292. data/lib/middleman-core/templates/html5/source/apple-touch-icon-57x57-precomposed.png +0 -0
  293. data/lib/middleman-core/templates/html5/source/apple-touch-icon-72x72-precomposed.png +0 -0
  294. data/lib/middleman-core/templates/html5/source/apple-touch-icon-precomposed.png +0 -0
  295. data/lib/middleman-core/templates/html5/source/apple-touch-icon.png +0 -0
  296. data/lib/middleman-core/templates/html5/source/crossdomain.xml +25 -0
  297. data/lib/middleman-core/templates/html5/source/css/style.css +293 -0
  298. data/lib/middleman-core/templates/html5/source/favicon.ico +0 -0
  299. data/lib/middleman-core/templates/html5/source/humans.txt +43 -0
  300. data/lib/middleman-core/templates/html5/source/img/.gitignore +0 -0
  301. data/lib/middleman-core/templates/html5/source/index.html +67 -0
  302. data/lib/middleman-core/templates/html5/source/js/libs/jquery-1.7.1.js +9266 -0
  303. data/lib/middleman-core/templates/html5/source/js/libs/jquery-1.7.1.min.js +4 -0
  304. data/lib/middleman-core/templates/html5/source/js/libs/modernizr-2.5.3.min.js +4 -0
  305. data/lib/middleman-core/templates/html5/source/js/plugins.js +11 -0
  306. data/lib/middleman-core/templates/html5/source/js/script.js +8 -0
  307. data/lib/middleman-core/templates/html5/source/robots.txt +4 -0
  308. data/lib/middleman-core/templates/html5.rb +30 -0
  309. data/lib/middleman-core/templates/local.rb +28 -0
  310. data/lib/middleman-core/templates/mobile/source/404.html +37 -0
  311. data/lib/middleman-core/templates/mobile/source/README.markdown +21 -0
  312. data/lib/middleman-core/templates/mobile/source/crossdomain.xml +25 -0
  313. data/lib/middleman-core/templates/mobile/source/css/style.css +315 -0
  314. data/lib/middleman-core/templates/mobile/source/humans.txt +43 -0
  315. data/lib/middleman-core/templates/mobile/source/img/h/apple-touch-icon.png +0 -0
  316. data/lib/middleman-core/templates/mobile/source/img/h/splash.png +0 -0
  317. data/lib/middleman-core/templates/mobile/source/img/l/apple-touch-icon-precomposed.png +0 -0
  318. data/lib/middleman-core/templates/mobile/source/img/l/apple-touch-icon.png +0 -0
  319. data/lib/middleman-core/templates/mobile/source/img/l/splash.png +0 -0
  320. data/lib/middleman-core/templates/mobile/source/img/m/apple-touch-icon.png +0 -0
  321. data/lib/middleman-core/templates/mobile/source/index.html +92 -0
  322. data/lib/middleman-core/templates/mobile/source/js/libs/modernizr-custom.js +14 -0
  323. data/lib/middleman-core/templates/mobile/source/js/libs/respond.min.js +7 -0
  324. data/lib/middleman-core/templates/mobile/source/js/mylibs/helper.js +171 -0
  325. data/lib/middleman-core/templates/mobile/source/js/plugins.js +20 -0
  326. data/lib/middleman-core/templates/mobile/source/js/script.js +0 -0
  327. data/lib/middleman-core/templates/mobile/source/robots.txt +4 -0
  328. data/lib/middleman-core/templates/mobile/source/sitemap.xml +9 -0
  329. data/lib/middleman-core/templates/mobile/source/test/index.html +31 -0
  330. data/lib/middleman-core/templates/mobile/source/test/qunit/qunit.css +148 -0
  331. data/lib/middleman-core/templates/mobile/source/test/qunit/qunit.js +1265 -0
  332. data/lib/middleman-core/templates/mobile/source/test/tests.js +21 -0
  333. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/Readme.PDF +0 -0
  334. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/aspx/aspx1.snippet +31 -0
  335. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/aspx/aspx2.snippet +2 -0
  336. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/aspx/ga.aspx +195 -0
  337. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/aspx/sample.aspx +44 -0
  338. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/jsp/ga.jsp +225 -0
  339. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/jsp/jsp1.snippet +35 -0
  340. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/jsp/jsp2.snippet +2 -0
  341. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/jsp/sample.jsp +51 -0
  342. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/php/ga.php +176 -0
  343. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/php/php1.snippet +30 -0
  344. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/php/php2.snippet +4 -0
  345. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/php/sample.php +44 -0
  346. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/pl/ga.pl +195 -0
  347. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/pl/perl1.snippet +27 -0
  348. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/pl/perl2.snippet +1 -0
  349. data/lib/middleman-core/templates/mobile/source/tools/googleanalyticsformobile/pl/sample.pl +38 -0
  350. data/lib/middleman-core/templates/mobile/source/tools/mobile-bookmark-bubble/COPYING +202 -0
  351. data/lib/middleman-core/templates/mobile/source/tools/mobile-bookmark-bubble/bookmark_bubble.js +559 -0
  352. data/lib/middleman-core/templates/mobile/source/tools/mobile-bookmark-bubble/example/example.html +43 -0
  353. data/lib/middleman-core/templates/mobile/source/tools/mobile-bookmark-bubble/example/example.js +57 -0
  354. data/lib/middleman-core/templates/mobile/source/tools/mobile-bookmark-bubble/images/arrow.png +0 -0
  355. data/lib/middleman-core/templates/mobile/source/tools/mobile-bookmark-bubble/images/close.png +0 -0
  356. data/lib/middleman-core/templates/mobile/source/tools/mobile-bookmark-bubble/images/generate_base64_images +33 -0
  357. data/lib/middleman-core/templates/mobile/source/tools/mobile-bookmark-bubble/images/icon_calendar.png +0 -0
  358. data/lib/middleman-core/templates/mobile/source/tools/wspl/README +27 -0
  359. data/lib/middleman-core/templates/mobile/source/tools/wspl/databasefactory.js +45 -0
  360. data/lib/middleman-core/templates/mobile/source/tools/wspl/dbworker.js +324 -0
  361. data/lib/middleman-core/templates/mobile/source/tools/wspl/dbworker_test.html +393 -0
  362. data/lib/middleman-core/templates/mobile/source/tools/wspl/dbworkerstarter.js +32 -0
  363. data/lib/middleman-core/templates/mobile/source/tools/wspl/dbwrapper_gears.js +595 -0
  364. data/lib/middleman-core/templates/mobile/source/tools/wspl/dbwrapper_gears_test.html +404 -0
  365. data/lib/middleman-core/templates/mobile/source/tools/wspl/dbwrapper_html5.js +203 -0
  366. data/lib/middleman-core/templates/mobile/source/tools/wspl/dbwrapper_html5_test.html +468 -0
  367. data/lib/middleman-core/templates/mobile/source/tools/wspl/dbwrapperapi.js +202 -0
  368. data/lib/middleman-core/templates/mobile/source/tools/wspl/dbwrapperapi_test.html +51 -0
  369. data/lib/middleman-core/templates/mobile/source/tools/wspl/gears_resultset.js +71 -0
  370. data/lib/middleman-core/templates/mobile/source/tools/wspl/gears_resultset_test.html +86 -0
  371. data/lib/middleman-core/templates/mobile/source/tools/wspl/gears_transaction.js +196 -0
  372. data/lib/middleman-core/templates/mobile/source/tools/wspl/gears_transaction_test.html +221 -0
  373. data/lib/middleman-core/templates/mobile/source/tools/wspl/gearsutils.js +94 -0
  374. data/lib/middleman-core/templates/mobile/source/tools/wspl/gearsutils_test.html +84 -0
  375. data/lib/middleman-core/templates/mobile/source/tools/wspl/global_functions.js +72 -0
  376. data/lib/middleman-core/templates/mobile/source/tools/wspl/simplenotes/index.html +347 -0
  377. data/lib/middleman-core/templates/mobile/source/tools/wspl/simplenotes/simplenotes.js +503 -0
  378. data/lib/middleman-core/templates/mobile/source/tools/wspl/simplenotes/styles.css +66 -0
  379. data/lib/middleman-core/templates/mobile/source/tools/wspl/simplenotes/template.js +75 -0
  380. data/lib/middleman-core/templates/mobile.rb +25 -0
  381. data/lib/middleman-core/templates/shared/Gemfile.tt +3 -0
  382. data/lib/middleman-core/templates/shared/config.ru +4 -0
  383. data/lib/middleman-core/templates/shared/config.tt +92 -0
  384. data/lib/middleman-core/templates/shared/gitignore +14 -0
  385. data/lib/middleman-core/templates.rb +85 -0
  386. data/lib/middleman-core/util.rb +174 -0
  387. data/lib/middleman-core/vendor/hooks-0.2.0/CHANGES.textile +9 -0
  388. data/lib/middleman-core/vendor/hooks-0.2.0/Gemfile +3 -0
  389. data/lib/middleman-core/vendor/hooks-0.2.0/README.rdoc +107 -0
  390. data/lib/middleman-core/vendor/hooks-0.2.0/Rakefile +12 -0
  391. data/lib/middleman-core/vendor/hooks-0.2.0/hooks.gemspec +22 -0
  392. data/lib/middleman-core/vendor/hooks-0.2.0/lib/hooks/inheritable_attribute.rb +33 -0
  393. data/lib/middleman-core/vendor/hooks-0.2.0/lib/hooks.rb +109 -0
  394. data/lib/middleman-core/vendor/hooks-0.2.0/test/hooks_test.rb +141 -0
  395. data/lib/middleman-core/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb +55 -0
  396. data/lib/middleman-core/vendor/hooks-0.2.0/test/test_helper.rb +10 -0
  397. data/lib/middleman-core/version.rb +5 -0
  398. data/lib/middleman-core.rb +16 -0
  399. data/middleman-core-x86-mingw32.gemspec +38 -0
  400. data/middleman-core.gemspec +39 -0
  401. metadata +806 -0
@@ -0,0 +1,92 @@
1
+ ###
2
+ # Compass
3
+ ###
4
+
5
+ # Susy grids in Compass
6
+ # First: gem install susy --pre
7
+ # require 'susy'
8
+
9
+ # Change Compass configuration
10
+ # compass_config do |config|
11
+ # config.output_style = :compact
12
+ # end
13
+
14
+ ###
15
+ # Page options, layouts, aliases and proxies
16
+ ###
17
+
18
+ # Per-page layout changes:
19
+ #
20
+ # With no layout
21
+ # page "/path/to/file.html", :layout => false
22
+ #
23
+ # With alternative layout
24
+ # page "/path/to/file.html", :layout => :otherlayout
25
+ #
26
+ # A path which all have the same layout
27
+ # with_layout :admin do
28
+ # page "/admin/*"
29
+ # end
30
+
31
+ # Proxy (fake) files
32
+ # page "/this-page-has-no-template.html", :proxy => "/template-file.html" do
33
+ # @which_fake_page = "Rendering a fake page with a variable"
34
+ # end
35
+
36
+ ###
37
+ # Helpers
38
+ ###
39
+
40
+ # Automatic image dimensions on image_tag helper
41
+ # activate :automatic_image_sizes
42
+
43
+ # Methods defined in the helpers block are available in templates
44
+ # helpers do
45
+ # def some_helper
46
+ # "Helping"
47
+ # end
48
+ # end
49
+
50
+ <% if options[:css_dir] -%>
51
+ set :css_dir, '<%= options[:css_dir] -%>'
52
+ <% else -%>
53
+ # Change the CSS directory
54
+ # set :css_dir, "alternative_css_directory"
55
+ <% end -%>
56
+
57
+ <% if options[:js_dir] -%>
58
+ set :js_dir, '<%= options[:js_dir] -%>'
59
+ <% else -%>
60
+ # Change the JS directory
61
+ # set :js_dir, "alternative_js_directory"
62
+ <% end -%>
63
+
64
+ <% if options[:images_dir] -%>
65
+ set :images_dir, '<%= options[:images_dir] -%>'
66
+ <% else -%>
67
+ # Change the images directory
68
+ # set :images_dir, "alternative_image_directory"
69
+ <% end -%>
70
+
71
+ # Build-specific configuration
72
+ configure :build do
73
+ # For example, change the Compass output style for deployment
74
+ # activate :minify_css
75
+
76
+ # Minify Javascript on build
77
+ # activate :minify_javascript
78
+
79
+ # Enable cache buster
80
+ # activate :cache_buster
81
+
82
+ # Use relative URLs
83
+ # activate :relative_assets
84
+
85
+ # Compress PNGs after build
86
+ # First: gem install middleman-smusher
87
+ # require "middleman-smusher"
88
+ # activate :smusher
89
+
90
+ # Or use a different image path
91
+ # set :http_path, "/Content/images/"
92
+ end
@@ -0,0 +1,14 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the build directory
11
+ /build
12
+
13
+ # Ignore Sass' cache
14
+ /.sass-cache
@@ -0,0 +1,85 @@
1
+ # Use thor for template generation
2
+ require "thor"
3
+ require "thor/group"
4
+
5
+ # Templates namespace
6
+ module Middleman::Templates
7
+
8
+ # Static methods
9
+ class << self
10
+
11
+ # Get list of registered templates and add new ones
12
+ #
13
+ # Middleman::Templates.register(:ext_name, klass)
14
+ #
15
+ # @param [Symbol] name The name of the template
16
+ # @param [Class] klass The class to be executed for this template
17
+ # @return [Hash] List of registered templates
18
+ def register(name=nil, klass=nil)
19
+ @_template_mappings ||= {}
20
+ @_template_mappings[name] = klass if name && klass
21
+ @_template_mappings
22
+ end
23
+
24
+ # Middleman::Templates.register(name, klass)
25
+ alias :registered :register
26
+ end
27
+
28
+ # Base Template class. Handles basic options and paths.
29
+ class Base < ::Thor::Group
30
+ include Thor::Actions
31
+
32
+ def initialize(names, options)
33
+ super
34
+ source_paths << File.join(File.dirname(__FILE__), 'templates')
35
+ end
36
+
37
+ # Required path for the new project to be generated
38
+ argument :location, :type => :string
39
+
40
+ # Name of the template being used to generate the project.
41
+ class_option :template, :default => "default"
42
+
43
+ # Output a config.ru file for Rack if --rack is passed
44
+ class_option :rack, :type => :boolean, :default => false
45
+
46
+ # Write a Rack config.ru file for project
47
+ # @return [void]
48
+ def generate_rack!
49
+ return unless options[:rack]
50
+ template "shared/config.ru", File.join(location, "config.ru")
51
+ end
52
+
53
+ # Write a Bundler Gemfile file for project
54
+ # @return [void]
55
+ def generate_bundler!
56
+ template "shared/Gemfile.tt", File.join(location, "Gemfile")
57
+
58
+ inside(location) do
59
+ ::Middleman::Cli::Bundle.new.invoke(:bundle)
60
+ end unless ENV["TEST"]
61
+ end
62
+
63
+ # Output a .gitignore file
64
+ class_option :git, :type => :boolean, :default => true
65
+
66
+ # Write a .gitignore file for project
67
+ # @return [void]
68
+ def generate_gitignore!
69
+ return unless options[:git]
70
+ copy_file "shared/gitignore", File.join(location, ".gitignore")
71
+ end
72
+ end
73
+ end
74
+
75
+ # Default template
76
+ require "middleman-core/templates/default"
77
+
78
+ # HTML5 template
79
+ require "middleman-core/templates/html5"
80
+
81
+ # HTML5 Mobile template
82
+ require "middleman-core/templates/mobile"
83
+
84
+ # Local templates
85
+ require "middleman-core/templates/local"
@@ -0,0 +1,174 @@
1
+ # Our custom logger
2
+ require "middleman-core/logger"
3
+
4
+ # For instrumenting
5
+ require "active_support/notifications"
6
+
7
+ # Using Thor's indifferent hash access
8
+ require "thor"
9
+
10
+ # Core Pathname library used for traversal
11
+ require "pathname"
12
+
13
+ module Middleman
14
+
15
+ module Util
16
+
17
+ # The logger
18
+ #
19
+ # @return [Middleman::Logger] The logger
20
+ def self.logger(*args)
21
+ if !@_logger || args.length > 0
22
+ @_logger = ::Middleman::Logger.new(*args)
23
+ end
24
+
25
+ @_logger
26
+ end
27
+
28
+ # Facade for ActiveSupport/Notification
29
+ def self.instrument(name, payload={}, &block)
30
+ name << ".middleman" unless name =~ /\.middleman$/
31
+ ::ActiveSupport::Notifications.instrument(name, payload, &block)
32
+ end
33
+
34
+ # Recursively convert a normal Hash into a HashWithIndifferentAccess
35
+ #
36
+ # @private
37
+ # @param [Hash] data Normal hash
38
+ # @return [Thor::CoreExt::HashWithIndifferentAccess]
39
+ def self.recursively_enhance(data)
40
+ if data.is_a? Hash
41
+ data = ::Thor::CoreExt::HashWithIndifferentAccess.new(data)
42
+ data.each do |key, val|
43
+ data[key] = recursively_enhance(val)
44
+ end
45
+ data
46
+ elsif data.is_a? Array
47
+ data.each_with_index do |val, i|
48
+ data[i] = recursively_enhance(val)
49
+ end
50
+ data
51
+ else
52
+ data
53
+ end
54
+ end
55
+
56
+ # Normalize a path to not include a leading slash
57
+ # @param [String] path
58
+ # @return [String]
59
+ def self.normalize_path(path)
60
+ # The tr call works around a bug in Ruby's Unicode handling
61
+ path.sub(/^\//, "").tr('','')
62
+ end
63
+
64
+ # Extract the text of a Rack response as a string.
65
+ # Useful for extensions implemented as Rack middleware.
66
+ # @param response The response from #call
67
+ # @return [String] The whole response as a string.
68
+ def self.extract_response_text(response)
69
+ case(response)
70
+ when String
71
+ response
72
+ when Array
73
+ response.join
74
+ when Rack::Response
75
+ response.body.join
76
+ when Rack::File
77
+ File.read(response.path)
78
+ else
79
+ response.to_s
80
+ end
81
+ end
82
+
83
+ # Takes a matcher, which can be a literal string
84
+ # or a string containing glob expressions, or a
85
+ # regexp, or a proc, or anything else that responds
86
+ # to #match or #call, and returns whether or not the
87
+ # given path matches that matcher.
88
+ #
89
+ # @param matcher A matcher string/regexp/proc/etc
90
+ # @param path A path as a string
91
+ # @return [Boolean] Whether the path matches the matcher
92
+ def self.path_match(matcher, path)
93
+ if matcher.respond_to? :match
94
+ matcher.match path
95
+ elsif matcher.respond_to? :call
96
+ matcher.call path
97
+ else
98
+ File.fnmatch(matcher.to_s, path)
99
+ end
100
+ end
101
+
102
+ # Get a recusive list of files inside a set of paths.
103
+ # Works with symlinks.
104
+ #
105
+ # @param path A path string or Pathname
106
+ # @return [Array] An array of filenames
107
+ def self.all_files_under(*paths)
108
+ paths.flatten!
109
+ paths.map! { |p| Pathname(p) }
110
+ files = paths.select { |p| p.file? }
111
+ paths.select {|p| p.directory? }.each do |dir|
112
+ files << all_files_under(dir.children)
113
+ end
114
+ files.flatten
115
+ end
116
+
117
+ # Simple shared cache implementation
118
+ class Cache
119
+ # Initialize
120
+ def initialize
121
+ self.clear
122
+ end
123
+
124
+ # Either get the cached key or save the contents of the block
125
+ #
126
+ # @param key Anything Hash can use as a key
127
+ def fetch(*key)
128
+ @cache[key] ||= yield
129
+ end
130
+
131
+ # Whether the key is in the cache
132
+ #
133
+ # @param key Anything Hash can use as a key
134
+ # @return [Boolean]
135
+ def has_key?(key)
136
+ @cache.has_key?(key)
137
+ end
138
+
139
+ # Get a specific key
140
+ #
141
+ # @param key Anything Hash can use as a key
142
+ def get(key)
143
+ @cache[key]
144
+ end
145
+
146
+ # Array of keys
147
+ # @return [Array]
148
+ def keys
149
+ @cache.keys
150
+ end
151
+
152
+ # Clear the entire cache
153
+ # @return [void]
154
+ def clear
155
+ @cache = {}
156
+ end
157
+
158
+ # Set a specific key
159
+ #
160
+ # @param key Anything Hash can use as a key
161
+ # @param value Cached value
162
+ # @return [void]
163
+ def set(key, value)
164
+ @cache[key] = value
165
+ end
166
+
167
+ # Remove a specific key
168
+ # @param key Anything Hash can use as a key
169
+ def remove(*key)
170
+ @cache.delete(key)
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,9 @@
1
+ h2. 0.2.0
2
+
3
+ h3. Changes
4
+ * Callback blocks are now executed on the instance using @instance_exec@. If you need to access the class (former context) use @self.class@.
5
+
6
+ h2. 0.1.4
7
+
8
+ h3. Bugfixes
9
+ * An uninitialized @inheritable_attr@ doesn't crash since it is not cloned anymore. Note that an uncloneable attribute value still causes an exception.
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,107 @@
1
+ = Hooks
2
+
3
+ <em>Generic hooks with callbacks for Ruby.</em>
4
+
5
+
6
+ == Introduction
7
+
8
+ _Hooks_ lets you define hooks declaratively in your ruby class. You can add callbacks to your hook, which will be run as soon as _you_ run the hook!
9
+
10
+ It's almost like ActiveSupport::Callbacks but 76,6% less complex. Instead, it is not more than 60 lines of code, one method compilation, no +method_missing+ and no magic.
11
+
12
+ Also, you may pass additional arguments to your callbacks when invoking a hook.
13
+
14
+ == Example
15
+
16
+ Let's take... a cat.
17
+
18
+ require 'hooks'
19
+
20
+ class Cat
21
+ include Hooks
22
+
23
+ define_hook :after_dinner
24
+
25
+ Now you can add callbacks to your hook declaratively in your class.
26
+
27
+ after_dinner do
28
+ puts "Ice cream for #{self}!"
29
+ end
30
+
31
+ after_dinner :have_a_desert # => refers to Cat#have_a_desert
32
+
33
+ def have_a_desert
34
+ puts "Hell, yeah!"
35
+ end
36
+
37
+ This will run the block and <tt>#have_a_desert</tt> from above.
38
+
39
+ cat.run_hook :after_dinner
40
+ # => Ice cream for #<Cat:0x8df9d84>!
41
+ Hell, yeah!
42
+
43
+ Callback blocks and methods will be executed with instance context. Note how +self+ in the block refers to the Cat instance.
44
+
45
+
46
+ == Inheritance
47
+
48
+ Hooks are inherited, here's a complete example to put it all together.
49
+
50
+ class Garfield < Cat
51
+
52
+ after_dinner :want_some_more
53
+
54
+ def want_some_more
55
+ puts "Is that all?"
56
+ end
57
+ end
58
+
59
+
60
+ Garfield.new.run_hook :after_dinner
61
+ # => Ice cream for #<Cat:0x8df9d84>!
62
+ Hell, yeah!
63
+ Is that all?
64
+
65
+ Note how the callbacks are invoked in the order they were inherited.
66
+
67
+
68
+ == Options for Callbacks
69
+
70
+ You're free to pass any number of arguments to #run_callback, those will be passed to the callbacks.
71
+
72
+ cat.run_hook :before_dinner, cat, Time.now
73
+
74
+ The callbacks should be ready for receiving parameters.
75
+
76
+ before_dinner :wash_pawns
77
+ before_dinner do |who, when|
78
+ ...
79
+ end
80
+
81
+ def wash_pawns(who, when)
82
+
83
+
84
+ Not sure why a cat should have ice cream for dinner. Beside that, I was tempted naming this gem _hooker_.
85
+
86
+
87
+ == Installation
88
+
89
+ gem install hooks
90
+
91
+
92
+ == Anybody using it?
93
+
94
+ * Hooks is already used in [Apotomo:http://github.com/apotonick/apotomo], a hot widget framework for Rails. Look at +lib/apotomo/widget.rb+ for examples and into +lib/apotomo/tree_node.rb+ to learn how modules-driven code might benefit from hooks.
95
+
96
+ == Similar libraries
97
+
98
+ * http://github.com/nakajima/aspectory
99
+ * http://github.com/auser/backcall
100
+ * http://github.com/mmcgrana/simple_callbacks
101
+
102
+
103
+ == License
104
+
105
+ Copyright (c) 2010, Nick Sutterer
106
+
107
+ Released under the MIT License.
@@ -0,0 +1,12 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ desc 'Default: run unit tests.'
5
+ task :default => :test
6
+
7
+ desc 'Test the hooks plugin.'
8
+ Rake::TestTask.new(:test) do |test|
9
+ test.libs << 'test'
10
+ test.test_files = FileList['test/*_test.rb']
11
+ test.verbose = true
12
+ end
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path('../lib/', __FILE__)
2
+ $:.unshift lib unless $:.include?(lib)
3
+
4
+ require 'hooks'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "hooks"
8
+ s.version = Hooks::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Nick Sutterer"]
11
+ s.email = ["apotonick@gmail.com"]
12
+ s.homepage = "http://nicksda.apotomo.de/tag/hooks"
13
+ s.summary = %q{Generic hooks with callbacks for Ruby.}
14
+ s.description = %q{Declaratively define hooks, add callbacks and run them with the options you like.}
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_development_dependency "shoulda"
21
+ s.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,33 @@
1
+ module Hooks
2
+ module InheritableAttribute
3
+ # Creates an inheritable attribute with accessors in the singleton class. Derived classes inherit the
4
+ # attributes. This is especially helpful with arrays or hashes that are extended in the inheritance
5
+ # chain. Note that you have to initialize the inheritable attribute.
6
+ #
7
+ # Example:
8
+ #
9
+ # class Cat
10
+ # inheritable_attr :drinks
11
+ # self.drinks = ["Becks"]
12
+ #
13
+ # class Garfield < Cat
14
+ # self.drinks << "Fireman's 4"
15
+ #
16
+ # and then, later
17
+ #
18
+ # Cat.drinks #=> ["Becks"]
19
+ # Garfield.drinks #=> ["Becks", "Fireman's 4"]
20
+ def inheritable_attr(name)
21
+ instance_eval %Q{
22
+ def #{name}=(v)
23
+ @#{name} = v
24
+ end
25
+
26
+ def #{name}
27
+ return @#{name} unless superclass.respond_to?(:#{name}) and value = superclass.#{name}
28
+ @#{name} ||= value.clone # only do this once.
29
+ end
30
+ }
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,109 @@
1
+ require File.join(File.dirname(__FILE__), "hooks/inheritable_attribute")
2
+
3
+ # Almost like ActiveSupport::Callbacks but 76,6% less complex.
4
+ #
5
+ # Example:
6
+ #
7
+ # class CatWidget < Apotomo::Widget
8
+ # define_hook :after_dinner
9
+ #
10
+ # Now you can add callbacks to your hook declaratively in your class.
11
+ #
12
+ # after_dinner do puts "Ice cream!" end
13
+ # after_dinner :have_a_desert # => refers to CatWidget#have_a_desert
14
+ #
15
+ # Running the callbacks happens on instances. It will run the block and #have_a_desert from above.
16
+ #
17
+ # cat.run_hook :after_dinner
18
+ module Hooks
19
+ VERSION = "0.2.0"
20
+
21
+ def self.included(base)
22
+ base.extend InheritableAttribute
23
+ base.extend ClassMethods
24
+ end
25
+
26
+ module ClassMethods
27
+ def define_hook(name)
28
+ accessor_name = "_#{name}_callbacks"
29
+
30
+ setup_hook_accessors(accessor_name)
31
+ define_hook_writer(name, accessor_name)
32
+ end
33
+
34
+ # Like Hooks#run_hook but for the class. Note that +:callbacks+ must be class methods.
35
+ #
36
+ # Example:
37
+ #
38
+ # class Cat
39
+ # after_eight :grab_a_beer
40
+ #
41
+ # def self.grab_a_beer(*) # and so on...
42
+ #
43
+ # where <tt>Cat.run_hook :after_eight</tt> will call the class method +grab_a_beer+.
44
+ def run_hook(name, *args)
45
+ run_hook_for(name, self, *args)
46
+ end
47
+
48
+ def run_hook_for(name, scope, *args)
49
+ callbacks_for_hook(name).each do |callback|
50
+ if callback.kind_of? Symbol
51
+ scope.send(callback, *args)
52
+ else
53
+ scope.instance_exec(*args, &callback)
54
+ end
55
+ end
56
+ end
57
+
58
+ # Returns the callbacks for +name+. Handy if you want to run the callbacks yourself, say when
59
+ # they should be executed in another context.
60
+ #
61
+ # Example:
62
+ #
63
+ # def initialize
64
+ # self.class.callbacks_for_hook(:after_eight).each do |callback|
65
+ # instance_exec(self, &callback)
66
+ # end
67
+ #
68
+ # would run callbacks in the object _instance_ context, passing +self+ as block parameter.
69
+ def callbacks_for_hook(name)
70
+ send("_#{name}_callbacks")
71
+ end
72
+
73
+ private
74
+
75
+ def define_hook_writer(hook, accessor_name)
76
+ self.send(:define_method, hook.to_sym) do |&block|
77
+ if self.class.respond_to?(hook)
78
+ self.class.send(hook.to_sym, &block)
79
+ end
80
+ end
81
+
82
+ instance_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
83
+ def #{hook}(method=nil, &block)
84
+ #{accessor_name} << (block || method)
85
+ end
86
+ RUBY_EVAL
87
+ end
88
+
89
+ def setup_hook_accessors(accessor_name)
90
+ inheritable_attr(accessor_name)
91
+ send("#{accessor_name}=", []) # initialize ivar.
92
+ end
93
+ end
94
+
95
+ # Runs the callbacks (method/block) for the specified hook +name+. Additional arguments will
96
+ # be passed to the callback.
97
+ #
98
+ # Example:
99
+ #
100
+ # cat.run_hook :after_dinner, "i want ice cream!"
101
+ #
102
+ # will invoke the callbacks like
103
+ #
104
+ # desert("i want ice cream!")
105
+ # block.call("i want ice cream!")
106
+ def run_hook(name, *args)
107
+ self.class.run_hook_for(name, self, *args)
108
+ end
109
+ end