aura 0.0.1.pre10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. data/.gitignore +6 -0
  2. data/.travis.yml +3 -0
  3. data/Gemfile +2 -0
  4. data/HISTORY.md +95 -0
  5. data/README.md +53 -0
  6. data/Rakefile +27 -0
  7. data/Scribefile +8 -0
  8. data/app/css/_utilities.scss +88 -0
  9. data/app/css/admin.scss +21 -0
  10. data/app/css/admin/_settings.scss +136 -0
  11. data/app/css/admin/chrome.scss +208 -0
  12. data/app/css/admin/common.scss +78 -0
  13. data/app/css/admin/forms.scss +342 -0
  14. data/app/css/admin/jquery_wysiwyg.scss +96 -0
  15. data/app/css/admin/loading.scss +18 -0
  16. data/app/css/admin/meta.scss +42 -0
  17. data/app/css/admin/reset.scss +46 -0
  18. data/app/css/admin/sections.scss +79 -0
  19. data/app/css/admin/setup.scss +22 -0
  20. data/app/css/admin/sidebar.scss +136 -0
  21. data/app/css/admin/slug.scss +78 -0
  22. data/app/css/admin/uiscreen.scss +22 -0
  23. data/app/css/admin/wysiwyg_field.scss +11 -0
  24. data/app/css/admin_watermark.scss +23 -0
  25. data/app/css/default_home_page.scss +13 -0
  26. data/app/css/login.scss +47 -0
  27. data/app/helpers/admin_helpers.rb +59 -0
  28. data/app/helpers/flash_helpers.rb +86 -0
  29. data/app/helpers/form_builder_helpers.rb +9 -0
  30. data/app/helpers/html_helpers.rb +27 -0
  31. data/app/helpers/jquery_helpers.rb +26 -0
  32. data/app/helpers/main_helpers.rb +67 -0
  33. data/app/helpers/page_helpers.rb +92 -0
  34. data/app/helpers/template_helpers.rb +94 -0
  35. data/app/helpers/user_helpers.rb +45 -0
  36. data/app/init/admin.rb +34 -0
  37. data/app/init/extensions.rb +18 -0
  38. data/app/init/pistol.rb +11 -0
  39. data/app/init/sequel.rb +11 -0
  40. data/app/main.rb +106 -0
  41. data/app/migrations/page.rb +29 -0
  42. data/app/migrations/settings.rb +11 -0
  43. data/app/migrations/user.rb +13 -0
  44. data/app/models/page.rb +116 -0
  45. data/app/models/page_seed.rb +47 -0
  46. data/app/models/settings.rb +59 -0
  47. data/app/models/user.rb +60 -0
  48. data/app/routes/admin.rb +44 -0
  49. data/app/routes/css_js.rb +53 -0
  50. data/app/routes/design_tests.rb +15 -0
  51. data/app/routes/editor.rb +152 -0
  52. data/app/routes/site.rb +33 -0
  53. data/app/routes/user.rb +48 -0
  54. data/app/views/admin/_back_to_dashboard.haml +3 -0
  55. data/app/views/admin/dashboard.haml +46 -0
  56. data/app/views/admin/layout.haml +73 -0
  57. data/app/views/admin/settings.haml +40 -0
  58. data/app/views/admin/settings/database.haml +42 -0
  59. data/app/views/base/crumbs.haml +50 -0
  60. data/app/views/base/delete.haml +19 -0
  61. data/app/views/base/edit.haml +61 -0
  62. data/app/views/base/errors.haml +10 -0
  63. data/app/views/base/form.haml +11 -0
  64. data/app/views/base/list.haml +14 -0
  65. data/app/views/base/list_actions.haml +4 -0
  66. data/app/views/base/list_item.haml +7 -0
  67. data/app/views/base/nav.haml +36 -0
  68. data/app/views/base/new.haml +36 -0
  69. data/app/views/base/preview.haml +28 -0
  70. data/app/views/base/tabs.haml +12 -0
  71. data/app/views/default_home_page.haml +15 -0
  72. data/app/views/design_tests/admin_styles.haml +58 -0
  73. data/app/views/form_builder/builder.haml +29 -0
  74. data/app/views/page/edit.haml +29 -0
  75. data/app/views/page/form.haml +22 -0
  76. data/app/views/page/meta_form.haml +22 -0
  77. data/app/views/page/new.haml +26 -0
  78. data/app/views/user/edit.haml +52 -0
  79. data/app/views/user/form.haml +43 -0
  80. data/app/views/user/list.haml +11 -0
  81. data/app/views/user/login.haml +33 -0
  82. data/app/views/user/new.haml +25 -0
  83. data/app/views/user/welcome.haml +29 -0
  84. data/app/views/watermark/watermark.haml +16 -0
  85. data/aura.gemspec +36 -0
  86. data/bin/aura +8 -0
  87. data/config/database.rb +12 -0
  88. data/config/extensions.rb +5 -0
  89. data/config/scss.rb +14 -0
  90. data/config/user.rb +10 -0
  91. data/default/.gitignore +6 -0
  92. data/default/Gemfile +11 -0
  93. data/default/README.md +24 -0
  94. data/default/Rakefile +8 -0
  95. data/default/app/README +3 -0
  96. data/default/app/css/.gitignore +0 -0
  97. data/default/app/helpers/helpers.rb.example +9 -0
  98. data/default/app/js/.gitignore +0 -0
  99. data/default/app/migrations/model.rb.example +20 -0
  100. data/default/app/models/model.rb.example +11 -0
  101. data/default/app/models/page-ext.rb.example +17 -0
  102. data/default/app/routes/site.rb.example +5 -0
  103. data/default/app/views/hello.haml.example +1 -0
  104. data/default/config.ru +3 -0
  105. data/default/config/.gitignore +0 -0
  106. data/default/config/database.rb.example +30 -0
  107. data/default/config/extensions.rb +5 -0
  108. data/default/config/user.rb.example +10 -0
  109. data/default/db/.gitignore +0 -0
  110. data/default/init.rb +15 -0
  111. data/default/public/.gitignore +0 -0
  112. data/extensions/contact_form/migrations/contact_form.rb +13 -0
  113. data/extensions/contact_form/models/contact_form.rb +13 -0
  114. data/extensions/contact_form/routes/contact_form.rb +11 -0
  115. data/extensions/contact_form/views/contact_form/edit.haml +8 -0
  116. data/extensions/contact_form/views/contact_form/form.haml +3 -0
  117. data/extensions/contact_form/views/contact_form/nav.haml +42 -0
  118. data/extensions/contact_form/views/contact_form/responses.haml +20 -0
  119. data/extensions/contact_form/views/contact_form/tabs.haml +8 -0
  120. data/extensions/default_theme/css/theme/_settings.scss +3 -0
  121. data/extensions/default_theme/css/theme/chrome.scss +66 -0
  122. data/extensions/default_theme/css/theme/reset.scss +34 -0
  123. data/extensions/default_theme/css/theme/style.scss +3 -0
  124. data/extensions/default_theme/info.yml +2 -0
  125. data/extensions/default_theme/public/browse.png +0 -0
  126. data/extensions/default_theme/views/base/id_portfolio.haml +32 -0
  127. data/extensions/default_theme/views/base/show.haml +31 -0
  128. data/extensions/default_theme/views/errors/error.haml +9 -0
  129. data/extensions/default_theme/views/errors/not_found.haml +11 -0
  130. data/extensions/default_theme/views/layout.haml +33 -0
  131. data/lib/aura.rb +315 -0
  132. data/lib/aura/admin.rb +41 -0
  133. data/lib/aura/app.rb +4 -0
  134. data/lib/aura/cli.rb +19 -0
  135. data/lib/aura/cli/base.rb +89 -0
  136. data/lib/aura/cli/helpers.rb +32 -0
  137. data/lib/aura/editor.rb +30 -0
  138. data/lib/aura/extension.rb +189 -0
  139. data/lib/aura/files.rb +38 -0
  140. data/lib/aura/menu.rb +142 -0
  141. data/lib/aura/models.rb +80 -0
  142. data/lib/aura/public.rb +68 -0
  143. data/lib/aura/rendering.rb +134 -0
  144. data/lib/aura/seeder.rb +38 -0
  145. data/lib/aura/slugs.rb +87 -0
  146. data/lib/aura/subtype.rb +48 -0
  147. data/lib/aura/tasks.rb +24 -0
  148. data/lib/aura/tasks/common.rb +17 -0
  149. data/lib/aura/tasks/db.rake +54 -0
  150. data/lib/aura/utils.rb +81 -0
  151. data/lib/aura/version.rb +25 -0
  152. data/lib/core/hasharray.rb +65 -0
  153. data/lib/core/object_ext.rb +9 -0
  154. data/lib/sequel/plugins/aura_custom.rb +16 -0
  155. data/lib/sequel/plugins/aura_editable.rb +39 -0
  156. data/lib/sequel/plugins/aura_hierarchy.rb +82 -0
  157. data/lib/sequel/plugins/aura_model.rb +271 -0
  158. data/lib/sequel/plugins/aura_renderable.rb +42 -0
  159. data/lib/sequel/plugins/aura_sluggable.rb +103 -0
  160. data/lib/sequel/plugins/aura_subtyped.rb +83 -0
  161. data/lib/terra.rb +185 -0
  162. data/lib/terra/ext.rb +16 -0
  163. data/lib/terra/field.rb +98 -0
  164. data/lib/terra/fields.rb +122 -0
  165. data/lib/terra/fieldset.rb +93 -0
  166. data/lib/terra/form.rb +111 -0
  167. data/manual/configuration.md +42 -0
  168. data/manual/extensions.md +45 -0
  169. data/manual/files.md +70 -0
  170. data/manual/helpers.md +39 -0
  171. data/manual/index.md +65 -0
  172. data/manual/models.md +58 -0
  173. data/manual/recipes.md +38 -0
  174. data/manual/recipes/bundling_sample_data.md +30 -0
  175. data/manual/recipes/creating_themes.md +10 -0
  176. data/manual/recipes/using_markdown_or_textile.md +24 -0
  177. data/manual/routes.md +39 -0
  178. data/manual/theming.md +55 -0
  179. data/manual/views.md +128 -0
  180. data/public/hi.html +0 -0
  181. data/public/images/admin/back.png +0 -0
  182. data/public/images/admin/browse.png +0 -0
  183. data/public/images/admin/mock-bg.png +0 -0
  184. data/public/images/admin/top-loader.gif +0 -0
  185. data/public/images/admin/uiscreen-loader.gif +0 -0
  186. data/public/images/admin_icons/add.png +0 -0
  187. data/public/images/admin_icons/contact.png +0 -0
  188. data/public/images/admin_icons/dashboard.png +0 -0
  189. data/public/images/admin_icons/generic.png +0 -0
  190. data/public/images/admin_icons/home-12.png +0 -0
  191. data/public/images/admin_icons/page.png +0 -0
  192. data/public/images/admin_icons/settings.png +0 -0
  193. data/public/images/jquery.wysiwyg.gif +0 -0
  194. data/public/js/admin.form_builder.js +15 -0
  195. data/public/js/admin.js +62 -0
  196. data/public/js/admin.layout.js +53 -0
  197. data/public/js/admin.nav.js +241 -0
  198. data/public/js/admin.slug.js +46 -0
  199. data/public/js/admin.subpage.js +15 -0
  200. data/public/js/jquery.hashlisten.js +85 -0
  201. data/public/js/jquery.js +166 -0
  202. data/public/js/jquery.livenavigate.js +58 -0
  203. data/public/js/jquery.livequery.js +226 -0
  204. data/public/js/jquery.quickvalidate.js +164 -0
  205. data/public/js/jquery.tmpl.js +486 -0
  206. data/public/js/jquery.uiscreen.js +150 -0
  207. data/public/js/jquery.wysiwyg.js +2339 -0
  208. data/public/js/jqueryui.js +766 -0
  209. data/public/js/lib.dirty.js +11 -0
  210. data/public/js/lib.loading.js +23 -0
  211. data/public/js/lib.wysiwyg.js +155 -0
  212. data/public/js/underscore-1.1.7.js +27 -0
  213. data/test/app/app/css/test_raw.css +1 -0
  214. data/test/app/app/css/test_sass.sass +3 -0
  215. data/test/app/app/damogram.txt +1 -0
  216. data/test/app/app/js/test_coffee.coffee +4 -0
  217. data/test/app/app/js/test_javascript.js +4 -0
  218. data/test/app/init.rb +5 -0
  219. data/test/stories/admin_css_story.rb +18 -0
  220. data/test/stories/css_js_story.rb +29 -0
  221. data/test/stories/first_login_story.rb +29 -0
  222. data/test/stories/visit_story.rb +39 -0
  223. data/test/stories_helper.rb +58 -0
  224. data/test/test_cli_helper.rb +31 -0
  225. data/test/test_helper.rb +111 -0
  226. data/test/test_temp_helper.rb +9 -0
  227. data/test/unit/cli_test.rb +38 -0
  228. data/test/unit/dump_test.rb +14 -0
  229. data/test/unit/extensions_test.rb +18 -0
  230. data/test/unit/files_test.rb +14 -0
  231. data/test/unit/flash_helper_test.rb +36 -0
  232. data/test/unit/html_helper_test.rb +29 -0
  233. data/test/unit/jquery_helper_test.rb +18 -0
  234. data/test/unit/model_test.rb +34 -0
  235. data/test/unit/page_helpers_test.rb +36 -0
  236. data/test/unit/seeder_test.rb +15 -0
  237. data/test/unit/settings_test.rb +29 -0
  238. data/test/unit/slug_test.rb +39 -0
  239. data/test/unit/ss_migration_test.rb +14 -0
  240. data/test/unit/terra_test.rb +125 -0
  241. data/test/unit/utils_test.rb +11 -0
  242. data/vendor/sinatra-sequel/.gitignore +3 -0
  243. data/vendor/sinatra-sequel/COPYING +18 -0
  244. data/vendor/sinatra-sequel/README.md +84 -0
  245. data/vendor/sinatra-sequel/Rakefile +67 -0
  246. data/vendor/sinatra-sequel/lib/sinatra/sequel.rb +73 -0
  247. data/vendor/sinatra-sequel/sinatra-sequel.gemspec +39 -0
  248. data/vendor/sinatra-sequel/spec/spec_sinatra_sequel.rb +70 -0
  249. metadata +536 -0
@@ -0,0 +1,142 @@
1
+ class Aura
2
+ # Class: Menu (Aura)
3
+ # A menu.
4
+ #
5
+ # #### Accessing the singleton
6
+ # Doing Aura.admin.menu will get you the single instance of Aura::Menu.
7
+ #
8
+ # m = Aura.admin.menu #=> #<Aura::Menu ...>
9
+ #
10
+ # #### Adding menu items
11
+ # Use {Aura::Menu#add}.
12
+ #
13
+ # Aura.admin.menu.add "hello",
14
+ # :name => "Hello",
15
+ # :href => '/admin/lol',
16
+ # :icon => 'settings'
17
+ #
18
+ # #### Adding submenu items
19
+ # Add sub items by using the dot notation on the name.
20
+ #
21
+ # Aura.admin.menu.add "hello.subitem",
22
+ # :name => "Subitem",
23
+ # :href => '/admin/lol/sub',
24
+ # :icon => 'settings'
25
+ #
26
+ # #### Retrieving menu items
27
+ # Use {Aura::Menu.items}.
28
+ #
29
+ # Aura.admin.menu.items #=> Array of MenuItems
30
+ #
31
+ # item = Aura.admin.menu.get('hello')
32
+ # item.name
33
+ # item.href
34
+ # item.icon
35
+ # item.items # List of sub items
36
+ #
37
+ class Menu
38
+ # Method: add (Aura::Menu)
39
+ # Adds a menu item.
40
+ #
41
+ # ## Usage
42
+ # Aura.admin.menu.add 'key',
43
+ # :name => 'name',
44
+ # :href => '/url',
45
+ # :icon => 'icon_name' # <= optional
46
+ #
47
+ def add(key, options={})
48
+ path = key.to_s.split('.')
49
+ last = path.pop
50
+ node = root
51
+
52
+ path.each do |segment|
53
+ node = (node.raw_items[segment] ||= MenuItem.new)
54
+ end
55
+
56
+ node.raw_items[last] = MenuItem.new(options.merge(:path => path, :key => last))
57
+ end
58
+
59
+ # Method: items (Aura::Menu)
60
+ # Returns the root menu items.
61
+ #
62
+ # ## Usage
63
+ # Aura.admin.menu.items
64
+ #
65
+ # ## Description
66
+ # Returns instances of {Aura::MenuItem}.
67
+ #
68
+ def items
69
+ root.items
70
+ end
71
+
72
+ # Method: get (Aura::Menu)
73
+ # Returns a menu item of a given key.
74
+ #
75
+ # ## Usage
76
+ # Aura.admin.menu.get(keyname)
77
+ #
78
+ # ## Example
79
+ #
80
+ # #### Get and set
81
+ # Use {Aura::Menu#add} to add, then `get` to get.
82
+ #
83
+ # Aura.admin.menu.add "hello",
84
+ # :name => "Hello",
85
+ # :href => '/admin/lol',
86
+ # :icon => 'settings'
87
+ #
88
+ # item = Aura.admin.menu.get('hello') #=> #<MenuItem>
89
+ # item.name #=> "Hello"
90
+ # item.icon #=> "settings"
91
+ #
92
+ def get(key='')
93
+ path = key.to_s.split('.')
94
+ node = root
95
+ path.each { |segment| node = node.raw_items[segment] }
96
+ node
97
+ end
98
+
99
+ protected
100
+ def root
101
+ @root ||= MenuItem.new
102
+ end
103
+ end
104
+
105
+ # Class: MenuItem (Aura)
106
+ # A menu item.
107
+ #
108
+ # ## Description
109
+ # This is an OpenStruct.
110
+ #
111
+ # It will always have `.path` and `.key`.
112
+ # Optional items are `.name`, `.href`, and `.position`.
113
+ #
114
+ # Methods such as {Aura::Menu.items} and {Aura::Menu.get} return menu items.
115
+ #
116
+ class MenuItem < OpenStruct
117
+ def initialize(hash={})
118
+ super
119
+ self.items = Hash.new
120
+ end
121
+
122
+ def name
123
+ @table[:name] || self.key.capitalize
124
+ end
125
+
126
+ def raw_items
127
+ @table[:items]
128
+ end
129
+
130
+ def items
131
+ @table[:items].values.sort_by { |item| item.position.to_s || item.key }
132
+ end
133
+
134
+ def href
135
+ @table[:href].try(:call) || @table[:href] || R(:admin, *path.split('.'))
136
+ end
137
+ end
138
+ end
139
+
140
+ #Aura.admin.menu.add 'settings.db', :name => "Settings", :href => "/settings"
141
+ #Aura.admin.menu.get('settings') # list of MenuItems
142
+ #Aura.admin.menu.items
@@ -0,0 +1,80 @@
1
+ # Class: Models (Aura)
2
+ # Models.
3
+ #
4
+ # #### Finding models
5
+ # `Aura.models` returns a Models instance, which is enumerable.
6
+ #
7
+ # Aura.models #=> #<Aura::Models>
8
+ # Aura.models.map { |m| m.name }
9
+ #
10
+ # #### Find by name
11
+ # Use {Aura.models.get} or Ruby's `const_get`.
12
+ #
13
+ # Aura.models.get('contact_form') #=> ContactForm
14
+ # Aura.models.const_get(:ContactForm) #=> ContactForm
15
+ #
16
+ class Aura
17
+ class Models
18
+ include Enumerable
19
+
20
+ def each(&blk)
21
+ all.each &blk
22
+ end
23
+
24
+ # Class method: all (Aura::Models)
25
+ # Returns an array of all model classes.
26
+ #
27
+ # ## Example
28
+ # Aura.models.all.each do |m|
29
+ # # ...
30
+ # end
31
+ #
32
+ def all
33
+ @@all ||= Array.new
34
+ end
35
+
36
+ # Class method: get (Aura::Models)
37
+ # Returns a given model.
38
+ #
39
+ # ## Usage
40
+ # Aura::Models.get(name)
41
+ #
42
+ # ## Description
43
+ # Looks up the model `name` and returns the model class, or `nil`
44
+ # if it's not found.
45
+ #
46
+ # ## Example
47
+ # Aura::Models.get('contact_form') #=> Aura::Model::ContactForm
48
+ #
49
+ def get(name)
50
+ name = camelize(name) if name.downcase == name
51
+ begin
52
+ Object.const_get(name)
53
+ rescue NameError
54
+ nil
55
+ end
56
+ end
57
+
58
+ # Class method: reload! (Aura::Models)
59
+ # Ensures that models will get new columns the next time it's loaded.
60
+ #
61
+ def reload!
62
+ Aura.models.each { |m| m.send :set_columns, nil }
63
+ end
64
+
65
+ # Puts models in the global namespace.
66
+ # Don't use me.
67
+ #
68
+ def unpack
69
+ all.each do |model|
70
+ klass = model.name.split('::').last
71
+ Kernel.const_set(klass, model) unless Kernel.const_defined?(klass)
72
+ end
73
+ end
74
+
75
+ protected
76
+ def camelize(str)
77
+ str.split('_').map { |s| s.capitalize }.join('')
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,68 @@
1
+ # Sinatra plugin: Public (Aura)
2
+ # Allows apps to use more than one public folder.
3
+ #
4
+ # ## Description
5
+ # This is used by the {Main} application.
6
+ # This is a general-purpose plugin that can be used in other Sinatra
7
+ # projects.
8
+ #
9
+ # ## Usage
10
+ # class MyApp < Sinatra::Base
11
+ # register Aura::Public
12
+ #
13
+ # add_public path
14
+ # add_public path[, :prefix => PREFIX]
15
+ # end
16
+ #
17
+ # ## Example
18
+ #
19
+ # #### Add a public dir
20
+ # Just pass a path to `add_public`.
21
+ #
22
+ # class MyApp < Sinatra::Base
23
+ # add_public "#{root}/app/public"
24
+ # end
25
+ #
26
+ # #### Accessing
27
+ # This may be used to access `app/public/script.js`.
28
+ #
29
+ # $ curl http://localhost:4567/script.js
30
+ #
31
+ # #### Prefix
32
+ # Here's how you add a prefix.
33
+ #
34
+ # add_public "#{root}/js", :prefix => "javascripts/"
35
+ # $ curl http://localhost:4567/javascripts/app.js
36
+ #
37
+ class Aura
38
+ module Public
39
+ def self.registered(app)
40
+ app.extend ClassMethods
41
+ end
42
+
43
+ module ClassMethods
44
+ # Class method: add_public (Aura::Public)
45
+ # Adds a new public dir.
46
+ #
47
+ # ## Description
48
+ # See {Aura::Public} for usage and examples.
49
+ #
50
+ def add_public(dir, options={})
51
+ return unless File.directory?(dir)
52
+ prefix = options.delete(:prefix)
53
+
54
+ get "#{prefix}*" do |path|
55
+ begin
56
+ fname = File.join(dir, path)
57
+ pass unless File.file?(fname)
58
+ pass unless Utils.in_dir?(fname, dir)
59
+
60
+ send_file fname
61
+ rescue Errno::ENOENT => e
62
+ pass
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,134 @@
1
+ # Sinatra plugin: Rendering (Aura)
2
+ # Allows rendering from multiple engines or renderers.
3
+ #
4
+ # ## Usage
5
+ #
6
+ # #### Registering
7
+ #
8
+ # class Main < Sinatra::Base
9
+ # register Aura::Rendering
10
+ #
11
+ # # These two settings are optional.
12
+ # set :multi_views, [ './views', './skin/default' ]
13
+ # set :multi_engines, [ :erb, :haml ]
14
+ #
15
+ # #### Using show
16
+ # Using #show will automatically find the appropriate template, trying the
17
+ # following variations.
18
+ #
19
+ # get '/' do
20
+ # show :home
21
+ # end
22
+ # end
23
+ #
24
+ # # ./views/home.erb
25
+ # # ./views/home.haml
26
+ # # ./skin/default/home.erb
27
+ # # ./skin/default/home.haml
28
+ #
29
+ module Aura::Rendering
30
+ def self.registered(app)
31
+ views = app.views || './views'
32
+
33
+ app.set :multi_engines, Tilt.mappings.keys unless app.respond_to?(:template_engines)
34
+ app.set :multi_views, views unless app.respond_to?(:multi_views)
35
+
36
+ app.helpers Helpers
37
+ end
38
+
39
+ module Helpers
40
+ # Helper: layout (Helpers)
41
+ # Defines a layout to use.
42
+ def layout(what=nil)
43
+ @layout = what if what
44
+ @layout
45
+ end
46
+
47
+ # Helper: show (Helpers)
48
+ # Shows a given template.
49
+ #
50
+ # ## Usage
51
+ # show(template[, options[, locals])
52
+ # show(model, template[, options[, locals])
53
+ #
54
+ # ## Options
55
+ # You may pass +options[:engine]+ to specify which engines you will want
56
+ # to limit the search to. This defaults to +App.multi_engines+, or Tilt's
57
+ # supported engines if that's not defined.
58
+ #
59
+ # You may pass +options[:views]+ to specify which directories to scour.
60
+ # This defaults to +Main.multi_views+, or +Main.views+.
61
+ #
62
+ # #### Show a template
63
+ #
64
+ # show :home
65
+ #
66
+ # #### Show a model's view
67
+ # This example looks at `:'page/index'` and `:'base/index'`, using
68
+ # whichever it finds first
69
+ #
70
+ # page = Page['/about']
71
+ # show page, :index
72
+ #
73
+ # #### Limiting engines
74
+ #
75
+ # # HAML only
76
+ # show :home, engine: :haml
77
+ #
78
+ # # HAML or ERB, favoring HAML first
79
+ # show :home, engine: [:haml, :erb]
80
+ #
81
+ # #### Only certain paths
82
+ # Only look at certain paths
83
+ #
84
+ # show :home, views: [ './views', './skins/default' ]
85
+ #
86
+ def show(templates, *args, &block)
87
+ if templates.respond_to?(:templates_for)
88
+ templates = templates.templates_for(args.shift || 'index')
89
+ end
90
+
91
+ options = args.shift || {}
92
+ locals = args.shift || {}
93
+
94
+ paths = [*(options[:views] || settings.multi_views)].join(',')
95
+ engines = [*(options[:engine] || settings.multi_engines)].join(',')
96
+
97
+ @layout = options.delete(:layout)
98
+
99
+ get_engine = lambda { |template|
100
+ spec = "{#{paths}}/#{template}.{#{engines}}"
101
+ template = Dir[spec].first
102
+ return nil unless template
103
+
104
+ ext = File.extname(template)[1..-1].to_sym
105
+ options = settings.send(ext).merge(options) if settings.respond_to?(ext)
106
+
107
+ eng = Tilt[ext] or raise "Template engine not found: #{ext}"
108
+ [ template, eng ]
109
+ }
110
+
111
+ t = @template_cache.fetch templates, options do
112
+ template, engine = [*templates].inject(nil) do |e, t|
113
+ e ||= get_engine[t]
114
+ end
115
+
116
+ raise Errno::ENOENT.new(templates.inspect) unless template
117
+
118
+ engine.new(template, 0, options)
119
+ end
120
+
121
+ if t
122
+ out = t.render(self, locals, &block)
123
+
124
+ if @layout
125
+ layout, @layout = @layout, nil
126
+ out = show(layout, :layout => false) { out }
127
+ end
128
+
129
+ out
130
+ end
131
+ end
132
+ end
133
+ end
134
+
@@ -0,0 +1,38 @@
1
+ # Sinatra plugin: Seeder (Aura)
2
+ # To be refactored--this sucks
3
+ module Aura::Seeder
4
+ def self.registered(app)
5
+ app.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+ def flush!(&blk)
10
+ blk = lambda { |*a| } unless block_given?
11
+
12
+ tables = self.database.tables
13
+
14
+ tables.each do |table|
15
+ blk.call(:drop_table, table)
16
+ self.database.drop_table table
17
+ end
18
+ end
19
+
20
+ def seed(type=nil, &blk)
21
+ blk = lambda { |*a| } unless block_given?
22
+
23
+ Aura.models.each { |m|
24
+ blk.call :seed, m.title_plural
25
+ m.seed(type, &blk)
26
+ }
27
+ end
28
+
29
+ def seed!(type=nil, &blk)
30
+ blk = lambda { |*a| } unless block_given?
31
+
32
+ Aura.models.each { |m|
33
+ blk.call :seed, m.title_plural
34
+ m.seed!(type, &blk)
35
+ }
36
+ end
37
+ end
38
+ end