locomotive_cms 0.0.4.beta12 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. data/Gemfile +13 -15
  2. data/README.textile +4 -5
  3. data/app/controllers/admin/api_contents_controller.rb +1 -10
  4. data/app/controllers/admin/base_controller.rb +2 -2
  5. data/app/controllers/admin/cross_domain_sessions_controller.rb +4 -7
  6. data/app/controllers/admin/current_sites_controller.rb +0 -2
  7. data/app/controllers/admin/imports_controller.rb +19 -13
  8. data/app/controllers/admin/pages_controller.rb +1 -1
  9. data/app/controllers/admin/passwords_controller.rb +2 -2
  10. data/app/controllers/admin/sessions_controller.rb +2 -2
  11. data/app/controllers/admin/sites_controller.rb +0 -2
  12. data/app/controllers/admin/theme_assets_controller.rb +1 -1
  13. data/app/controllers/application_controller.rb +1 -1
  14. data/app/controllers/home_controller.rb +7 -0
  15. data/app/helpers/admin/assets_helper.rb +6 -0
  16. data/app/helpers/admin/custom_fields_helper.rb +2 -2
  17. data/app/helpers/admin/{box_helper.rb → login_helper.rb} +3 -7
  18. data/app/models/asset_collection.rb +3 -15
  19. data/app/models/content_instance.rb +0 -19
  20. data/app/models/content_type.rb +3 -21
  21. data/app/models/extensions/page/tree.rb +7 -63
  22. data/app/models/page.rb +0 -2
  23. data/app/models/site.rb +3 -15
  24. data/app/uploaders/asset_uploader.rb +1 -1
  25. data/app/uploaders/theme_asset_uploader.rb +1 -12
  26. data/app/views/admin/asset_collections/edit.html.haml +2 -2
  27. data/app/views/admin/asset_collections/new.html.haml +1 -1
  28. data/app/views/admin/assets/_form.html.haml +2 -2
  29. data/app/views/admin/content_types/_form.html.haml +2 -2
  30. data/app/views/admin/content_types/new.html.haml +1 -1
  31. data/app/views/admin/contents/_form.html.haml +2 -2
  32. data/app/views/admin/contents/index.html.haml +1 -1
  33. data/app/views/admin/cross_domain_sessions/new.html.haml +1 -1
  34. data/app/views/admin/current_sites/_form.html.haml +3 -3
  35. data/app/views/admin/current_sites/edit.html.haml +1 -1
  36. data/app/views/admin/imports/new.html.haml +0 -11
  37. data/app/views/admin/imports/show.html.haml +1 -1
  38. data/app/views/admin/my_accounts/edit.html.haml +1 -1
  39. data/app/views/admin/pages/_form.html.haml +3 -2
  40. data/app/views/admin/pages/_page.html.haml +2 -4
  41. data/app/views/admin/pages/index.html.haml +1 -1
  42. data/app/views/admin/passwords/edit.html.haml +2 -2
  43. data/app/views/admin/passwords/new.html.haml +2 -2
  44. data/app/views/admin/sessions/new.html.haml +2 -2
  45. data/app/views/admin/shared/_head.html.haml +5 -4
  46. data/app/views/admin/shared/menu/_contents.html.haml +1 -1
  47. data/app/views/admin/sites/_form.html.haml +3 -3
  48. data/app/views/admin/snippets/_form.html.haml +2 -2
  49. data/app/views/admin/snippets/index.html.haml +15 -0
  50. data/app/views/admin/theme_assets/_form.html.haml +2 -2
  51. data/app/views/admin/theme_assets/index.html.haml +1 -1
  52. data/app/views/home/show.html.haml +4 -0
  53. data/app/views/{admin/layouts → layouts/admin}/application.html.haml +0 -0
  54. data/app/views/layouts/admin/box.html.haml +19 -0
  55. data/app/views/layouts/application.html.haml +7 -0
  56. data/config/application.rb +3 -1
  57. data/config/environments/development.rb +6 -1
  58. data/config/environments/production.rb +1 -1
  59. data/config/environments/test.rb +5 -1
  60. data/config/initializers/locomotive.rb +0 -14
  61. data/config/locales/admin_ui_en.yml +1 -33
  62. data/config/locales/admin_ui_fr.yml +1 -34
  63. data/config/locales/default_en.yml +0 -1
  64. data/config/locales/default_fr.yml +0 -1
  65. data/config/locales/flash.en.yml +0 -1
  66. data/config/locales/flash.fr.yml +0 -1
  67. data/config/mongoid.yml +5 -13
  68. data/config/routes.rb +1 -6
  69. data/lib/generators/locomotive/copy_assets/copy_assets_generator.rb +14 -0
  70. data/lib/generators/locomotive/install/install_generator.rb +10 -18
  71. data/lib/generators/locomotive/install/templates/README +13 -23
  72. data/lib/generators/locomotive/install/templates/locomotive.rb +1 -15
  73. data/lib/locomotive/carrierwave.rb +0 -1
  74. data/lib/locomotive/configuration.rb +1 -3
  75. data/lib/locomotive/custom_fields.rb +1 -0
  76. data/lib/locomotive/delayed_job.rb +2 -1
  77. data/lib/locomotive/engine.rb +7 -24
  78. data/lib/locomotive/heroku.rb +0 -1
  79. data/lib/locomotive/httparty/webservice.rb +1 -12
  80. data/lib/locomotive/import.rb +0 -2
  81. data/lib/locomotive/import/asset_collections.rb +8 -40
  82. data/lib/locomotive/import/assets.rb +12 -20
  83. data/lib/locomotive/import/content_types.rb +15 -51
  84. data/lib/locomotive/import/job.rb +11 -106
  85. data/lib/locomotive/import/pages.rb +26 -79
  86. data/lib/locomotive/import/site.rb +5 -3
  87. data/lib/locomotive/import/snippets.rb +8 -6
  88. data/lib/locomotive/inherited_resources.rb +0 -1
  89. data/lib/locomotive/liquid/drops/asset_collections.rb +4 -4
  90. data/lib/locomotive/liquid/drops/contents.rb +16 -21
  91. data/lib/locomotive/liquid/drops/page.rb +0 -4
  92. data/lib/locomotive/liquid/filters/html.rb +29 -15
  93. data/lib/locomotive/liquid/tags/consume.rb +1 -1
  94. data/lib/locomotive/liquid/tags/nav.rb +17 -48
  95. data/lib/locomotive/liquid/tags/paginate.rb +3 -3
  96. data/lib/locomotive/middlewares/fonts.rb +11 -3
  97. data/lib/locomotive/misc_form_builder.rb +7 -2
  98. data/lib/locomotive/regexps.rb +1 -1
  99. data/lib/locomotive/render.rb +3 -9
  100. data/lib/locomotive/routing/site_dispatcher.rb +6 -10
  101. data/lib/locomotive/version.rb +1 -2
  102. data/public/images/admin/box/buttons/right_bg.png +0 -0
  103. data/public/javascripts/admin/aloha/VERSION.txt +1 -1
  104. data/public/javascripts/admin/aloha/aloha-nodeps.js +101 -140
  105. data/public/javascripts/admin/aloha/aloha.js +105 -193
  106. data/public/javascripts/admin/aloha/css/aloha.css +4 -65
  107. data/public/javascripts/admin/aloha/deps/prettyPhoto/resources/css/prettyPhoto.css +2 -2
  108. data/public/javascripts/admin/aloha/i18n/de.dict +0 -2
  109. data/public/javascripts/admin/aloha/i18n/en.dict +0 -2
  110. data/public/javascripts/admin/aloha/images/base.png +0 -0
  111. data/public/javascripts/admin/aloha/images/base_multi.png +0 -0
  112. data/public/javascripts/admin/aloha/images/fade_in.png +0 -0
  113. data/public/javascripts/admin/aloha/images/fade_out.png +0 -0
  114. data/public/javascripts/admin/aloha/images/gentics_logo.png +0 -0
  115. data/public/javascripts/admin/aloha/images/grabhandle.png +0 -0
  116. data/public/javascripts/admin/aloha/images/maximize.png +0 -0
  117. data/public/javascripts/admin/aloha/images/pin.png +0 -0
  118. data/public/javascripts/admin/aloha/images/removeformat.png +0 -0
  119. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/de.dict +2 -0
  120. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/en.dict +2 -0
  121. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/eo.dict +2 -0
  122. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/fi.dict +2 -0
  123. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/fr.dict +2 -0
  124. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/i18n/it.dict +2 -0
  125. data/public/javascripts/admin/aloha/plugins/com.example.aloha.DummyDC/plugin.js +7 -0
  126. data/public/javascripts/admin/aloha/plugins/{com.example.aloha.plugins.Save → com.example.aloha.DummySave}/i18n/de.dict +0 -0
  127. data/public/javascripts/admin/aloha/plugins/{com.example.aloha.plugins.Save → com.example.aloha.DummySave}/i18n/en.dict +0 -0
  128. data/public/javascripts/admin/aloha/plugins/{com.example.aloha.plugins.Save → com.example.aloha.DummySave}/i18n/fi.dict +0 -0
  129. data/public/javascripts/admin/aloha/plugins/{com.example.aloha.plugins.Save → com.example.aloha.DummySave}/i18n/fr.dict +0 -0
  130. data/public/javascripts/admin/aloha/plugins/{com.example.aloha.plugins.Save → com.example.aloha.DummySave}/i18n/it.dict +0 -0
  131. data/public/javascripts/admin/aloha/plugins/{com.example.aloha.plugins.Save → com.example.aloha.DummySave}/plugin.js +0 -0
  132. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Format/plugin.js +1 -1
  133. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/de.dict +20 -0
  134. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/en.dict +20 -0
  135. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/eo.dict +16 -0
  136. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/fi.dict +20 -0
  137. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/fr.dict +16 -0
  138. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/i18n/it.dict +20 -0
  139. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.GCN/plugin.js +7 -0
  140. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.HighlightEditables/plugin.js +1 -1
  141. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/css/jquery.autocomplete.css +48 -0
  142. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/deps/jquery.autocomplete.js +1 -0
  143. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/plugin.js +1 -1
  144. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/ressource.js +7 -0
  145. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/ressourcedummy.js +7 -0
  146. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/ressourceregistry.js +7 -0
  147. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.List/plugin.js +1 -1
  148. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.TOC/plugin.js +1 -1
  149. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/i18n/de.dict +0 -2
  150. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/i18n/en.dict +0 -2
  151. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/plugin.js +1 -1
  152. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/resources/table.css +110 -28
  153. data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Loader/plugin.js +1 -0
  154. data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/i18n/en.dict +2 -0
  155. data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/i18n/fi.dict +2 -0
  156. data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/i18n/fr.dict +2 -0
  157. data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/person.css +3 -0
  158. data/public/javascripts/admin/aloha/plugins/eu.iksproject.plugins.Person/plugin.js +1 -0
  159. data/public/javascripts/admin/aloha/plugins/simpletable/plugin.js.deactivated +2330 -0
  160. data/public/javascripts/admin/asset_collections.js +7 -11
  161. data/public/javascripts/admin/contents.js +1 -3
  162. data/public/javascripts/admin/site.js +3 -9
  163. data/public/javascripts/admin/snippets.js +1 -1
  164. data/public/javascripts/admin/utils.js +3 -5
  165. data/public/stylesheets/admin/application.css +1 -1
  166. data/public/stylesheets/admin/box.css +5 -5
  167. data/public/stylesheets/admin/buttons.css +5 -0
  168. data/public/stylesheets/admin/formtastic_changes.css +12 -5
  169. data/public/stylesheets/admin/inline_editor.css +5 -22
  170. data/public/stylesheets/admin/layout.css +4 -9
  171. metadata +130 -187
  172. data/app/controllers/admin/installation_controller.rb +0 -79
  173. data/app/uploaders/theme_uploader.rb +0 -19
  174. data/app/views/admin/errors/no_page.html.haml +0 -1
  175. data/app/views/admin/errors/no_site.html.haml +0 -1
  176. data/app/views/admin/installation/step_1.html.haml +0 -24
  177. data/app/views/admin/installation/step_2.html.haml +0 -26
  178. data/app/views/admin/installation/step_3.html.haml +0 -23
  179. data/app/views/admin/layouts/box.html.haml +0 -21
  180. data/app/views/admin/layouts/error.html.haml +0 -1
  181. data/config/assets.yml +0 -96
  182. data/config/initializers/carrierwave.rb +0 -17
  183. data/lib/locomotive/import/base.rb +0 -46
  184. data/lib/locomotive/import/logger.rb +0 -13
  185. data/lib/locomotive/railties/tasks.rake +0 -16
  186. data/public/javascripts/admin/aloha/i18n/pl.dict +0 -5
  187. data/public/javascripts/admin/aloha/images/base_big.png +0 -0
  188. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/examples/triSports.css +0 -86
  189. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/examples/triSports.html +0 -44
  190. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/i18n/de.dict +0 -4
  191. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/i18n/en.dict +0 -4
  192. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/i18n/fr.dict +0 -4
  193. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/plugin.js +0 -1
  194. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/product.js +0 -1
  195. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/2xu-wetsuit.jpg +0 -0
  196. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/asics-noosa.jpg +0 -0
  197. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/fivefingers-kso.jpg +0 -0
  198. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/kuota-kueen-k.jpg +0 -0
  199. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/mizuno-wave-musha2.jpg +0 -0
  200. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/product.css +0 -69
  201. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/product_button.gif +0 -0
  202. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/simplon-mrt.jpg +0 -0
  203. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/trek-fuel-ex.jpg +0 -0
  204. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/trisports.jpg +0 -0
  205. data/public/javascripts/admin/aloha/plugins/com.example.aloha.plugins.Product/resources/zoggs-predator.jpg +0 -0
  206. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/examples/AlohaAbbr.css +0 -48
  207. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/examples/AlohaAbbr.html +0 -69
  208. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/i18n/de.dict +0 -4
  209. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/i18n/en.dict +0 -4
  210. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Abbr/plugin.js +0 -7
  211. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Format/i18n/pl.dict +0 -30
  212. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/LinkList.js +0 -7
  213. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/delicious.js +0 -7
  214. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/i18n/pl.dict +0 -4
  215. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/css/LinkChecker.css +0 -14
  216. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/examples/AlohaLinkChecker.css +0 -49
  217. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/examples/AlohaLinkChecker.html +0 -82
  218. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/i18n/en.dict +0 -27
  219. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/plugin.js +0 -7
  220. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.LinkChecker/proxy.php +0 -235
  221. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Paste/plugin.js +0 -7
  222. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Paste/wordpastehandler.js +0 -7
  223. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.TOC/i18n/de.dict +0 -1
  224. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.TOC/i18n/en.dict +0 -1
  225. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/i18n/pl.dict +0 -12
  226. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/resources/wai_green.png +0 -0
  227. data/public/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Table/resources/wai_red.png +0 -0
  228. data/public/stylesheets/admin/installation.css +0 -50
  229. data/public/stylesheets/admin/safari.css +0 -15
@@ -1,11 +1,13 @@
1
1
  module Locomotive
2
2
  module Import
3
- class Pages < Base
3
+ module Pages
4
+
5
+ def self.process(context)
6
+ site, pages, theme_path = context[:site], context[:database]['pages'], context[:theme_path]
4
7
 
5
- def process
6
8
  context[:done] = {} # initialize the hash storing pages already processed
7
9
 
8
- self.add_index_and_404
10
+ self.add_index_and_404(context)
9
11
 
10
12
  Dir[File.join(theme_path, 'templates', '**/*')].each do |template_path|
11
13
 
@@ -13,50 +15,43 @@ module Locomotive
13
15
 
14
16
  next if %w(index 404).include?(fullpath)
15
17
 
16
- self.add_page(fullpath)
18
+ self.add_page(fullpath, context)
17
19
  end
18
20
  end
19
21
 
20
- protected
22
+ def self.add_page(fullpath, context)
23
+ puts "....adding #{fullpath}"
21
24
 
22
- def add_page(fullpath)
23
25
  page = context[:done][fullpath]
24
26
 
25
27
  return page if page # already added, so skip it
26
28
 
29
+ site, pages, theme_path = context[:site], context[:database]['site']['pages'], context[:theme_path]
30
+
27
31
  template = File.read(File.join(theme_path, 'templates', "#{fullpath}.liquid")) rescue "Unable to find #{fullpath}.liquid"
28
32
 
29
- self.replace_images!(template)
33
+ self.build_parent_template(template, context)
30
34
 
31
- self.build_parent_template(template)
35
+ parent = self.find_parent(fullpath, context)
32
36
 
33
- parent = self.find_parent(fullpath)
37
+ page = site.pages.where(:fullpath => fullpath).first || site.pages.build
34
38
 
35
39
  attributes = {
36
40
  :title => fullpath.split('/').last.humanize,
37
41
  :slug => fullpath.split('/').last,
38
42
  :parent => parent,
39
- :raw_template => template,
40
- :published => true
41
- }.merge(self.pages[fullpath] || {}).symbolize_keys
43
+ :raw_template => template
44
+ }.merge(pages[fullpath] || {}).symbolize_keys
42
45
 
43
46
  # templatized ?
44
47
  if content_type_slug = attributes.delete(:content_type)
45
- fullpath.gsub!(/\/template$/, '/content_type_template')
46
- attributes.merge!({
47
- :templatized => true,
48
- :content_type => site.content_types.where(:slug => content_type_slug).first
49
- })
48
+ attributes[:content_type] = site.content_types.where(:slug => content_type_slug).first
50
49
  end
51
50
 
52
- page = site.pages.where(:fullpath => fullpath).first || site.pages.build
53
-
54
51
  page.attributes = attributes
55
52
 
56
53
  page.save!
57
54
 
58
- self.log "adding #{page.fullpath} / #{page.position}"
59
-
60
55
  site.reload
61
56
 
62
57
  context[:done][fullpath] = page
@@ -64,7 +59,7 @@ module Locomotive
64
59
  page
65
60
  end
66
61
 
67
- def build_parent_template(template)
62
+ def self.build_parent_template(template, context)
68
63
  # just check if the template contains the extends keyword
69
64
  fullpath = template.scan(/\{% extends (\w+) %\}/).flatten.first
70
65
 
@@ -73,11 +68,13 @@ module Locomotive
73
68
 
74
69
  return if fullpath == 'parent'
75
70
 
76
- self.add_page(fullpath)
71
+ self.add_page(fullpath, context)
77
72
  end
78
73
  end
79
74
 
80
- def find_parent(fullpath)
75
+ def self.find_parent(fullpath, context)
76
+ site = context[:site]
77
+
81
78
  segments = fullpath.split('/')
82
79
 
83
80
  return site.pages.index.first if segments.size == 1
@@ -89,10 +86,12 @@ module Locomotive
89
86
  # look for a local index page in db
90
87
  parent = site.pages.where(:fullpath => parent_fullpath).first
91
88
 
92
- parent || self.add_page(parent_fullpath)
89
+ parent || self.add_page(parent_fullpath, context)
93
90
  end
94
91
 
95
- def add_index_and_404
92
+ def self.add_index_and_404(context)
93
+ site, pages, theme_path = context[:site], context[:database]['site']['pages'], context[:theme_path]
94
+
96
95
  %w(index 404).each_with_index do |slug, position|
97
96
  page = site.pages.where({ :slug => slug, :depth => 0 }).first
98
97
 
@@ -100,11 +99,7 @@ module Locomotive
100
99
 
101
100
  template = File.read(File.join(theme_path, 'templates', "#{slug}.liquid"))
102
101
 
103
- self.replace_images!(template)
104
-
105
- page.attributes = { :raw_template => template }.merge(self.pages[slug] || {})
106
-
107
- page.position = position
102
+ page.attributes = { :raw_template => template, :position => position }.merge(pages[slug] || {})
108
103
 
109
104
  page.save! rescue nil # TODO better error handling
110
105
 
@@ -114,54 +109,6 @@ module Locomotive
114
109
  end
115
110
  end
116
111
 
117
- def replace_images!(template)
118
- return if template.blank?
119
-
120
- template.gsub!(/\/samples\/(.*\.[a-zA-Z0-9]{3})/) do |match|
121
- name = $1
122
-
123
- collection = AssetCollection.find_or_create_internal(site)
124
-
125
- if asset = collection.assets.detect { |a| a.source_filename == name }
126
- asset.source.url
127
- else
128
- match
129
- end
130
- end
131
- end
132
-
133
- def pages
134
- @pages ||= self.retrieve_pages
135
- end
136
-
137
- def retrieve_pages
138
- pages = context[:database]['site']['pages']
139
-
140
- if pages.is_a?(Array) # ordered list of pages
141
- tmp, positions = {}, Hash.new(0)
142
- pages.each do |data|
143
- position = nil
144
- fullpath = data.keys.first.to_s
145
-
146
- unless %w(index 404).include?(fullpath)
147
- (segments = fullpath.split('/')).pop
148
- position_key = segments.empty? ? 'index' : segments.join('/')
149
-
150
- position = positions[position_key]
151
-
152
- positions[position_key] += 1
153
- end
154
-
155
- attributes = (data.values.first || {}).merge(:position => position)
156
-
157
- tmp[fullpath] = attributes
158
- end
159
- pages = tmp
160
- end
161
-
162
- pages
163
- end
164
-
165
112
  end
166
113
  end
167
114
  end
@@ -1,9 +1,11 @@
1
1
  module Locomotive
2
2
  module Import
3
- class Site < Base
3
+ module Site
4
4
 
5
- def process
6
- attributes = database['site'].clone.delete_if { |name, value| %w{name pages assets content_types asset_collections}.include?(name) }
5
+ def self.process(context)
6
+ site, database = context[:site], context[:database]
7
+
8
+ attributes = database['site'].clone.delete_if { |name, value| %w{pages assets content_types asset_collections}.include?(name) }
7
9
 
8
10
  site.attributes = attributes
9
11
 
@@ -1,18 +1,20 @@
1
1
  module Locomotive
2
2
  module Import
3
- class Snippets < Base
3
+ module Snippets
4
+
5
+ def self.process(context)
6
+ site, theme_path = context[:site], context[:theme_path]
4
7
 
5
- def process
6
8
  Dir[File.join(theme_path, 'snippets', '*')].each do |snippet_path|
7
- self.log "path = #{snippet_path}"
8
9
 
9
10
  name = File.basename(snippet_path, File.extname(snippet_path)).parameterize('_')
10
-
11
+
11
12
  snippet = site.snippets.where(:slug => name).first || site.snippets.build(:name => name)
12
13
 
13
- snippet.template = File.read(snippet_path) # = site.snippets.create! :name => name, :template =>
14
-
14
+ snippet.template = File.read(snippet_path) # = site.snippets.create! :name => name, :template =>
15
+
15
16
  snippet.save!
17
+ # puts "snippet = #{snippet.inspect}"
16
18
  end
17
19
  end
18
20
 
@@ -1,4 +1,3 @@
1
- require 'responders'
2
1
  require 'inherited_resources'
3
2
  require 'inherited_resources/actions'
4
3
  require 'inherited_resources/responder'
@@ -18,19 +18,19 @@ module Locomotive
18
18
  end
19
19
 
20
20
  def first
21
- @collection.ordered_assets.first
21
+ @collection.assets.first
22
22
  end
23
23
 
24
24
  def last
25
- @collection.ordered_assets.last
25
+ @collection.assets.last
26
26
  end
27
27
 
28
28
  def each(&block)
29
- @collection.ordered_assets.each(&block)
29
+ @collection.assets.each(&block)
30
30
  end
31
31
 
32
32
  def paginate(options = {})
33
- paginated_collection = @collection.ordered_assets.paginate(options)
33
+ paginated_collection = @collection.assets.paginate(options)
34
34
  {
35
35
  :collection => paginated_collection,
36
36
  :current_page => paginated_collection.current_page,
@@ -18,34 +18,20 @@ module Locomotive
18
18
  end
19
19
 
20
20
  def first
21
- self.collection.first
21
+ content = @content_type.ordered_contents(@context['with_scope']).first
22
22
  end
23
23
 
24
24
  def last
25
- self.collection.last
25
+ content = @content_type.ordered_contents(@context['with_scope']).last
26
26
  end
27
27
 
28
28
  def each(&block)
29
- self.collection.each(&block)
30
- end
31
-
32
- def api
33
- { 'create' => @context.registers[:controller].send('admin_api_contents_url', @content_type.slug) }
34
- end
35
-
36
- def before_method(meth)
37
- klass = @content_type.contents.klass # delegate to the proxy class
38
- if (meth.to_s =~ /^group_by_.+$/) == 0
39
- klass.send(meth, :ordered_contents)
40
- else
41
- klass.send(meth)
42
- end
29
+ @collection ||= @content_type.ordered_contents(@context['with_scope'])
30
+ @collection.each(&block)
43
31
  end
44
32
 
45
- protected
46
-
47
33
  def paginate(options = {})
48
- @collection = self.collection.paginate(options)
34
+ @collection ||= @content_type.ordered_contents(@context['with_scope']).paginate(options)
49
35
  {
50
36
  :collection => @collection,
51
37
  :current_page => @collection.current_page,
@@ -57,8 +43,17 @@ module Locomotive
57
43
  }
58
44
  end
59
45
 
60
- def collection
61
- @collection ||= @content_type.ordered_contents(@context['with_scope'])
46
+ def api
47
+ { 'create' => @context.registers[:controller].send('admin_api_contents_url', @content_type.slug) }
48
+ end
49
+
50
+ def before_method(meth)
51
+ klass = @content_type.contents.klass # delegate to the proxy class
52
+ if (meth.to_s =~ /^group_by_.+$/) == 0
53
+ klass.send(meth, :ordered_contents)
54
+ else
55
+ klass.send(meth)
56
+ end
62
57
  end
63
58
  end
64
59
  end
@@ -19,10 +19,6 @@ module Locomotive
19
19
  @fullpath ||= @source.fullpath
20
20
  end
21
21
 
22
- def depth
23
- @source.depth
24
- end
25
-
26
22
  end
27
23
  end
28
24
  end
@@ -9,7 +9,11 @@ module Locomotive
9
9
  return '' if input.nil?
10
10
 
11
11
  unless input =~ /^(\/|http:)/
12
- input = asset_url("stylesheets/#{input}")
12
+ segments = "stylesheets/#{input}".split('/')
13
+
14
+ filename, folder = segments.pop, segments.join('/')
15
+
16
+ input = asset_url(folder, filename)
13
17
  end
14
18
 
15
19
  input = "#{input}.css" unless input.ends_with?('.css')
@@ -23,7 +27,14 @@ module Locomotive
23
27
  return '' if input.nil?
24
28
 
25
29
  unless input =~ /^(\/|http:)/
26
- input = asset_url("javascripts/#{input}")
30
+ segments = "javascripts/#{input}".split('/')
31
+
32
+ filename, folder = segments.pop, segments.join('/')
33
+
34
+ input = asset_url(folder, filename)
35
+ # javascript = ThemeAsset.new(:site => @context.registers[:site], :folder => folder)
36
+ #
37
+ # input = '/' + ThemeAssetUploader.new(javascript).store_path(filename)
27
38
  end
28
39
 
29
40
  input = "#{input}.js" unless input.ends_with?('.js')
@@ -36,14 +47,18 @@ module Locomotive
36
47
 
37
48
  input = "images/#{input}" unless input.starts_with?('/')
38
49
 
39
- asset_url(input)
50
+ segments = input.split('/')
51
+
52
+ filename, folder = segments.pop, segments.join('/')
53
+
54
+ asset_url(folder, filename)
40
55
  end
41
56
 
42
57
  # Write an image tag
43
58
  # input: url of the image OR asset drop
44
59
  def image_tag(input, *args)
45
60
  image_options = inline_options(args_to_options(args))
46
- "<img src=\"#{get_url_from_asset(input)}\" #{image_options}/>"
61
+ "<img src=\"#{File.join('/', get_url_from_asset(input))}\" #{image_options}/>"
47
62
  end
48
63
 
49
64
  # Embed a flash movie into a page
@@ -68,13 +83,10 @@ module Locomotive
68
83
 
69
84
  options = args_to_options(args)
70
85
 
71
- previous_label = options[:previous_label] || I18n.t('pagination.previous')
72
- next_label = options[:next_label] || I18n.t('pagination.next')
73
-
74
86
  previous_link = (if paginate['previous'].blank?
75
- "<span class=\"disabled prev_page\">#{previous_label}</span>"
87
+ "<span class=\"disabled prev_page\">#{I18n.t('pagination.previous')}</span>"
76
88
  else
77
- "<a href=\"#{paginate['previous']['url']}\" class=\"prev_page\">#{previous_label}</a>"
89
+ "<a href=\"#{paginate['previous']['url']}\" class=\"prev_page\">#{I18n.t('pagination.previous')}</a>"
78
90
  end)
79
91
 
80
92
  links = ""
@@ -89,9 +101,9 @@ module Locomotive
89
101
  end
90
102
 
91
103
  next_link = (if paginate['next'].blank?
92
- "<span class=\"disabled next_page\">#{next_label}</span>"
104
+ "<span class=\"disabled next_page\">#{I18n.t('pagination.next')}</span>"
93
105
  else
94
- "<a href=\"#{paginate['next']['url']}\" class=\"next_page\">#{next_label}</a>"
106
+ "<a href=\"#{paginate['next']['url']}\" class=\"next_page\">#{I18n.t('pagination.next')}</a>"
95
107
  end)
96
108
 
97
109
  %{<div class="pagination #{options[:css]}">
@@ -119,7 +131,7 @@ module Locomotive
119
131
  # <key1>="<value1>", <key2>="<value2", ...etc
120
132
  def inline_options(options = {})
121
133
  return '' if options.empty?
122
- (options.stringify_keys.sort.to_a.collect { |a, b| "#{a}=\"#{b}\"" }).join(' ') << ' '
134
+ (options.stringify_keys.to_a.collect { |a, b| "#{a}=\"#{b}\"" }).join(' ') << ' '
123
135
  end
124
136
 
125
137
  # Get the url to be used in html tags such as image_tag, flash_tag, ...etc
@@ -128,10 +140,12 @@ module Locomotive
128
140
  input.respond_to?(:url) ? input.url : input
129
141
  end
130
142
 
131
- def asset_url(path)
132
- ThemeAssetUploader.url_for(@context.registers[:site], path)
143
+ def asset_url(folder, filename)
144
+ asset = ThemeAsset.new(:site => @context.registers[:site], :folder => folder)
145
+ uploader = ThemeAssetUploader.new(asset)
146
+ uploader.retrieve_from_store!(filename)
147
+ uploader.url
133
148
  end
134
-
135
149
  end
136
150
 
137
151
  ::Liquid::Template.register_filter(Html)
@@ -39,7 +39,7 @@ module Locomotive
39
39
  protected
40
40
 
41
41
  def render_all_and_cache_it(context)
42
- Rails.cache.fetch(@cache_key, :expires_in => @expires_in, :force => @expires_in == 0) do
42
+ Rails.cache.fetch(@cache_key, :expires_in => @expires_in) do
43
43
  context.stack do
44
44
  context.scopes.last[@target.to_s] = Locomotive::Httparty::Webservice.consume(@url, @options.symbolize_keys)
45
45
 
@@ -1,26 +1,22 @@
1
1
  module Locomotive
2
2
  module Liquid
3
3
  module Tags
4
- # Display the children pages of the site, current page or the parent page. If not precised, nav is applied on the current page.
4
+ # Display the children pages of the site or the current page. If not precised, nav is applied on the current page.
5
5
  # The html output is based on the ul/li tags.
6
6
  #
7
7
  # Usage:
8
8
  #
9
9
  # {% nav site %} => <ul class="nav"><li class="on"><a href="/features">Features</a></li></ul>
10
10
  #
11
- # {% nav site, no_wrapper: true, exclude: 'contact|about', id: 'main-nav' }
12
- #
13
11
  class Nav < ::Liquid::Tag
14
12
 
15
13
  Syntax = /(#{::Liquid::Expression}+)?/
16
14
 
17
15
  def initialize(tag_name, markup, tokens, context)
18
16
  if markup =~ Syntax
19
- @source = ($1 || 'page').gsub(/"|'/, '')
20
- @options = { :id => 'nav' }
21
- markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/"|'/, '') }
22
-
23
- @options[:exclude] = Regexp.new(@options[:exclude]) if @options[:exclude]
17
+ @site_or_page = $1 || 'page'
18
+ @options = {}
19
+ markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value }
24
20
  else
25
21
  raise ::Liquid::SyntaxError.new("Syntax Error in 'nav' - Valid syntax: nav <page|site> <options>")
26
22
  end
@@ -29,61 +25,34 @@ module Locomotive
29
25
  end
30
26
 
31
27
  def render(context)
32
- children_output = []
33
-
34
- entries = fetch_entries(context)
28
+ @current_page = context.registers[:page]
35
29
 
36
- entries.each_with_index do |p, index|
37
- css = []
38
- css << 'first' if index == 0
39
- css << 'last' if index == entries.size - 1
30
+ source = context.registers[@site_or_page.to_sym]
40
31
 
41
- children_output << render_entry_link(p, css.join(' '))
42
- end
32
+ # puts "#{@site_or_page.to_sym} / source = #{source.inspect}"
43
33
 
44
- output = children_output.join("\n")
45
-
46
- if @options[:no_wrapper] != 'true'
47
- output = %{<ul id="#{@options[:id]}">\n#{output}</ul>}
34
+ if source.respond_to?(:name) # site ?
35
+ source = source.pages.index.first # start from home page
36
+ else
37
+ source = source.parent || source
48
38
  end
49
39
 
40
+ output = %{<ul id="nav">}
41
+ output += source.children.map { |p| render_child_link(p) }.join("\n")
42
+ output += %{</ul>}
50
43
  output
51
44
  end
52
45
 
53
46
  private
54
47
 
55
- def fetch_entries(context)
56
- @current_page = context.registers[:page]
57
-
58
- children = (case @source
59
- when 'site' then context.registers[:site].pages.index.minimal_attributes.first # start from home page
60
- when 'parent' then @current_page.parent || @current_page
61
- when 'page' then @current_page
62
- else
63
- context.registers[:site].pages.fullpath(@source).minimal_attributes.first
64
- end).children_with_minimal_attributes.to_a
65
-
66
- children.delete_if { |p| !include_page?(p) }
67
- end
68
-
69
- def include_page?(page)
70
- if page.templatized? || !page.published?
71
- false
72
- elsif @options[:exclude]
73
- (page.fullpath =~ @options[:exclude]).nil?
74
- else
75
- true
76
- end
77
- end
78
-
79
- def render_entry_link(page, css)
80
- selected = @current_page.fullpath =~ /^#{page.fullpath}/ ? ' on' : ''
48
+ def render_child_link(page)
49
+ selected = @current_page._id == page._id ? ' on' : ''
81
50
 
82
51
  icon = @options[:icon] ? '<span></span>' : ''
83
52
  label = %{#{icon if @options[:icon] != 'after' }#{page.title}#{icon if @options[:icon] == 'after' }}
84
53
 
85
54
  %{
86
- <li id="#{page.slug.dasherize}" class="link#{selected} #{css}">
55
+ <li id="#{page.slug.dasherize}" class="link#{selected}">
87
56
  <a href="/#{page.fullpath}">#{label}</a>
88
57
  </li>
89
58
  }.strip