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,47 @@
1
+ class Page < Sequel::Model
2
+ def self.seed(type=nil, &blk)
3
+ super
4
+
5
+ return unless type == :sample
6
+
7
+ blk.call :info, "Creating sample pages..."
8
+
9
+ require "ffaker"
10
+ lorem = lambda { Faker::Lorem.paragraphs(3).map { |s| "<p>#{s}</p>" }.join("\n\n") }
11
+
12
+ p1 = self.create :title => "Home",
13
+ :slug => "home",
14
+ :body => lorem.call
15
+
16
+ p1 = self.create :title => "About us",
17
+ :slug => "about-us",
18
+ :body => lorem.call
19
+
20
+ p1 = self.create :title => "Products",
21
+ :slug => "products",
22
+ :body => lorem.call
23
+
24
+ [ "Sony iPhone", "Blackberry iXUS",
25
+ "Canon Vostro", "Nokia Curve"
26
+ ].each do |product|
27
+ p2 = self.create :title => product,
28
+ :parent_id => p1.id,
29
+ :body => lorem.call
30
+ [ "8GB Black", "8GB White", "16GB 3G", "16GB Wifi" ].each do |type|
31
+ p3 = self.create :title => type,
32
+ :parent_id => p2.id,
33
+ :body => lorem.call
34
+ end
35
+ end
36
+
37
+ p1 = self.create :title => "Employees",
38
+ :slug => "employees",
39
+ :body => lorem.call
40
+
41
+ 8.times {
42
+ p2 = self.create :title => Faker::Name.name,
43
+ :parent_id => p1.id,
44
+ :body => lorem.call
45
+ }
46
+ end
47
+ end
@@ -0,0 +1,59 @@
1
+ # Model: Setting
2
+ # A setting.
3
+ #
4
+ # ## Description
5
+ # You don't need to use this model directly. Just use:
6
+ #
7
+ # * {Aura.set}
8
+ # * {Aura.get}
9
+ #
10
+ class Setting < Sequel::Model
11
+ plugin :serialization, :yaml, :value
12
+
13
+ def self.seed(type=nil, &blk)
14
+ super
15
+ Aura.default :'site.name', "My Site"
16
+ end
17
+
18
+ # Class method: get (Setting)
19
+ # Returns the value of a certain key.
20
+ #
21
+ # The get, set, default and delete methods are accessible from the
22
+ # Aura class.
23
+ #
24
+ def self.get(key)
25
+ find(:key => key.to_s).try(:value)
26
+ end
27
+
28
+ # Class method: del (Setting)
29
+ # Deletes a key.
30
+ #
31
+ def self.del(key)
32
+ s = find(:key => key.to_s)
33
+ return if s.nil?
34
+
35
+ value = s.value
36
+ s.delete
37
+ value
38
+ end
39
+
40
+ # Class method: set (Setting)
41
+ # Sets the value of a key.
42
+ #
43
+ def self.set(key, value)
44
+ s = find(:key => key.to_s) || new
45
+ s.key = key
46
+ s.value = value
47
+ s.save
48
+ value
49
+ end
50
+
51
+ # Class method: default (Setting)
52
+ # Sets the default value of a key.
53
+ #
54
+ def self.default(key, value)
55
+ s = find(:key => key.to_s)
56
+ return set(key, value) if s.nil?
57
+ get key
58
+ end
59
+ end
@@ -0,0 +1,60 @@
1
+ # Model: User
2
+ # A user.
3
+ #
4
+ class User < Sequel::Model
5
+ plugin :aura_editable
6
+
7
+ extend Shield::Model
8
+
9
+ # For Shield
10
+ def self.fetch(email)
11
+ first(:email => email)
12
+ end
13
+
14
+ # For Shield
15
+ def password=(password)
16
+ self.crypted_password = Shield::Password.encrypt(password)
17
+ @password = password
18
+ @password_confirmation = password if new?
19
+ end
20
+
21
+ attr_writer :password_confirmation
22
+
23
+ # For Shield
24
+ def validate
25
+ super
26
+ validates_presence :email
27
+ errors.add(:password, 'cannot be empty') if self.crypted_password.nil?
28
+
29
+ duplicate = self.class.fetch(email)
30
+ errors.add(:email, 'is already taken') if !duplicate.nil? and duplicate.id != self.id
31
+ errors.add(:password_confirmation, 'must match password') if @password != @password_confirmation
32
+ end
33
+
34
+ def slugify(str=email)
35
+ super str
36
+ end
37
+
38
+ def to_s
39
+ email
40
+ end
41
+
42
+ def self.seed!(type=nil, &blk)
43
+ # Don't clear users!
44
+ seed type, &blk
45
+ end
46
+
47
+ def self.seed(type=nil, &blk)
48
+ super
49
+ return if User.any?
50
+
51
+ email = Main.default_user
52
+ password = Main.default_password
53
+
54
+ p1 = self.create :email => email,
55
+ :password => password,
56
+ :password_confirmation => password
57
+
58
+ blk.call :info, "You may login with '#{email}' and password '#{password}'." if block_given?
59
+ end
60
+ end
@@ -0,0 +1,44 @@
1
+ class Main
2
+ get '/admin' do
3
+ require_login
4
+ show_admin :'admin/dashboard'
5
+ end
6
+
7
+ get '/admin/settings' do
8
+ require_login
9
+ show_admin :'admin/settings'
10
+ end
11
+
12
+ get '/admin/settings/database' do
13
+ require_login
14
+ show_admin :'admin/settings/database'
15
+ end
16
+
17
+ get '/admin/settings/database/backup.yml' do
18
+ content_type :yaml
19
+ attachment "backup.#{Time.now.strftime('%Y%m%d')}.yml"
20
+ Aura::db_dump_yaml
21
+ end
22
+
23
+ post '/admin/settings/database/seed' do
24
+ require_login
25
+
26
+ Main.seed!(:sample)
27
+
28
+ flash_message "Sample data loaded!"
29
+ redirect R(:admin)
30
+ end
31
+
32
+ post '/admin/settings/database/flush' do
33
+ require_login
34
+
35
+ Main.flush!
36
+ Main.seed!
37
+
38
+ flash_message "Everything has been cleared. Welcome to your new fresh site!"
39
+
40
+ # Log in as the test user.
41
+ session[:user] = User.first.try(:id)
42
+ redirect R(:admin, :welcome)
43
+ end
44
+ end
@@ -0,0 +1,53 @@
1
+ class Main
2
+ helpers do
3
+ def render_from_app(fname, type, types=[])
4
+ exts = ([type] + types).join(',')
5
+
6
+ fn = Aura.files.glob("#{type}/#{fname}.{#{exts}}").first or return
7
+
8
+ extension = File.extname(fn)[1..-1].to_sym # :sass
9
+ if extension == type
10
+ send_file fn
11
+ else
12
+ content_type type
13
+ render extension, File.read(fn)
14
+ end
15
+ end
16
+
17
+ # Try to #show something
18
+ def render_from_view(what, type, engines=[:sass])
19
+ out = show :"#{type}/#{what}", :engine => engines
20
+
21
+ content_type type
22
+ out
23
+ rescue Errno::ENOENT => e
24
+ nil
25
+ end
26
+
27
+ def dirty_glob?(str)
28
+ %w(* .. { } [ ]).any? { |sym| str.include?(sym) }
29
+ end
30
+ end
31
+
32
+ get '/css/*.css' do |fname|
33
+ pass if dirty_glob?(fname)
34
+
35
+ engines = %w(sass scss less)
36
+ type = :css
37
+
38
+ x = render_from_app( fname, type, engines)
39
+ x ||= render_from_view(fname, type, engines)
40
+ x || pass
41
+ end
42
+
43
+ get '/js/*.js' do |fname|
44
+ pass if dirty_glob?(fname)
45
+
46
+ engines = %w(coffee)
47
+ type = :js
48
+
49
+ x = render_from_app( fname, type, engines)
50
+ x ||= render_from_view(fname, type, engines)
51
+ x || pass
52
+ end
53
+ end
@@ -0,0 +1,15 @@
1
+ class Main
2
+ configure :development do
3
+ get '/design_tests' do
4
+ spec = Main.root_path('{app,extensions/*}', 'views', 'design_tests', '*')
5
+ names = Dir[spec].map { |f| File.basename(f).gsub(/\.[^\.]*$/, '') }
6
+ names.map do |name|
7
+ "<li><a href='/design_test/#{name}'>#{name}</a></li>"
8
+ end
9
+ end
10
+
11
+ get '/design_test/:test' do |test|
12
+ show :"design_tests/#{test}"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,152 @@
1
+ class Main
2
+ get '/:model/list' do |model|
3
+ require_login
4
+ @model = Aura.models.get(model) or pass
5
+ pass unless @model.try(:editable?)
6
+
7
+ show_admin @model, :list,
8
+ :model => @model
9
+ end
10
+
11
+ get '/:model/new' do |model|
12
+ require_login
13
+ @model = Aura.models.get(model) or pass
14
+ pass unless @model.try(:editable?)
15
+
16
+ @item = @model.new
17
+
18
+ show_admin @model, 'new',
19
+ :model => @model,
20
+ :parent => nil,
21
+ :item => @item,
22
+ :action => @model.path(:new)
23
+ end
24
+
25
+ post '/:model/new' do |model|
26
+ require_login
27
+ @model = Aura.models.get(model) or pass
28
+ pass unless @model.try(:editable?)
29
+
30
+ begin
31
+ @item = @model.new
32
+ @item.update params[:editor]
33
+ @item.save
34
+ flash_message "The new item has been created."
35
+
36
+ rescue Sequel::ValidationFailed
37
+ return show_admin(@model.templates_for('new'),
38
+ :model => @model,
39
+ :parent => nil,
40
+ :item => @item,
41
+ :action => @model.path(:new))
42
+ end
43
+
44
+ redirect params[:next] || @item.path(:edit)
45
+ end
46
+
47
+ get '/*/edit' do |path|
48
+ require_login
49
+ @item = Aura.find(path) or pass
50
+ pass unless @item.try(:editable?)
51
+
52
+ show_admin @item, 'edit',
53
+ :item => @item,
54
+ :action => @item.path(:edit)
55
+ end
56
+
57
+ post '/*/edit' do |path|
58
+ require_login
59
+ @item = Aura.find(path) or pass
60
+ pass unless @item.try(:editable?)
61
+
62
+ begin
63
+ @item.set_fields params[:editor]
64
+
65
+ unless params[:no_save]
66
+ @item.save
67
+ flash_message "Your edits have been saved."
68
+ end
69
+
70
+ return redirect(params[:next]) unless params[:next].nil?
71
+
72
+ rescue Sequel::ValidationFailed
73
+ end
74
+
75
+ show_admin @item, 'edit',
76
+ :item => @item,
77
+ :action => @item.path(:edit)
78
+ end
79
+
80
+ get '/*/preview' do |path|
81
+ require_login
82
+ @item = Aura.find(path) or pass
83
+ pass unless @item.try(:editable?)
84
+
85
+ show_admin @item, 'preview',
86
+ :item => @item
87
+ end
88
+
89
+ get '/*/new' do |path|
90
+ require_login
91
+ @parent = Aura.find(path) or pass
92
+ pass unless @parent.try(:parentable?)
93
+ pass unless @parent.try(:editable?)
94
+
95
+ @model = @parent.class
96
+
97
+ show_admin @model, 'new',
98
+ :model => @model,
99
+ :item => @model.new(:parent => @parent),
100
+ :parent => @parent,
101
+ :action => @parent.path(:new)
102
+ end
103
+
104
+ post '/*/new' do |path|
105
+ require_login
106
+ @parent = Aura.find(path) or pass
107
+ pass unless @parent.try(:parentable?)
108
+ pass unless @parent.try(:editable?)
109
+
110
+ @model = @parent.class
111
+
112
+ begin
113
+ @item = @model.new(:parent => @parent)
114
+ @item.update params[:editor]
115
+
116
+ raise 1 unless params[:no_save].nil?
117
+ @item.save
118
+ flash_message "The new item has been created."
119
+
120
+ rescue => e
121
+ return show_admin(@item, 'new',
122
+ :model => @model,
123
+ :item => @item,
124
+ :parent => @parent,
125
+ :action => @parent.path(:new))
126
+ end
127
+
128
+ redirect params[:next] || @item.path(:edit)
129
+ end
130
+
131
+ get '/*/delete' do |path|
132
+ require_login
133
+ @item = Aura.find(path) or pass
134
+ pass unless @item.try(:editable?)
135
+
136
+ show_admin @item, 'delete',
137
+ :item => @item,
138
+ :action => @item.path(:delete)
139
+ end
140
+
141
+ post '/*/delete' do |path|
142
+ require_login
143
+ @item = Aura.find(path) or pass
144
+ pass unless @item.try(:editable?)
145
+
146
+ action = @item.parent? ? @item.parent.path(:edit) : R(:admin)
147
+ @item.delete
148
+ flash_message "The item has been deleted."
149
+
150
+ redirect params[:next] || action
151
+ end
152
+ end
@@ -0,0 +1,33 @@
1
+ class Main
2
+ helpers do
3
+ def load_path(path)
4
+ @item = Aura.find(path) or pass
5
+ pass unless @item.try(:renderable?)
6
+
7
+ show @item.page_templates, {}, :item => @item
8
+ end
9
+ end
10
+
11
+ get '/*' do |path|
12
+ load_path path
13
+ end
14
+
15
+ get '/' do
16
+ path = '/home'
17
+
18
+ # Do we have a homepage?
19
+ if Aura.find(path).nil?
20
+ return show(:'default_home_page', :layout => false)
21
+ end
22
+
23
+ load_path(path)
24
+ end
25
+
26
+ not_found do
27
+ [ 404, show('errors/not_found') ]
28
+ end
29
+
30
+ #error 500 do
31
+ # error 500, show('errors/error')
32
+ #end
33
+ end