locomotivecms_steam 0.1.2.pre.beta → 1.0.0.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (355) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.travis.yml +8 -1
  4. data/Gemfile +17 -8
  5. data/Gemfile.lock +160 -113
  6. data/LICENSE +1 -1
  7. data/README.md +36 -15
  8. data/Rakefile +27 -1
  9. data/bin/steam.rb +97 -0
  10. data/config/locales/en.yml +2 -1
  11. data/config/locales/fr.yml +2 -1
  12. data/lib/locomotive/steam.rb +28 -19
  13. data/lib/locomotive/steam/adapters/concerns/key.rb +15 -0
  14. data/lib/locomotive/steam/adapters/filesystem.rb +124 -0
  15. data/lib/locomotive/steam/adapters/filesystem/sanitizer.rb +54 -0
  16. data/lib/locomotive/steam/adapters/filesystem/sanitizers/content_entry.rb +86 -0
  17. data/lib/locomotive/steam/adapters/filesystem/sanitizers/content_type.rb +21 -0
  18. data/lib/locomotive/steam/adapters/filesystem/sanitizers/page.rb +160 -0
  19. data/lib/locomotive/steam/adapters/filesystem/sanitizers/simple.rb +15 -0
  20. data/lib/locomotive/steam/adapters/filesystem/sanitizers/snippet.rb +33 -0
  21. data/lib/locomotive/steam/adapters/filesystem/simple_cache_store.rb +38 -0
  22. data/lib/locomotive/steam/adapters/filesystem/yaml_loader.rb +47 -0
  23. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_entry.rb +87 -0
  24. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_type.rb +96 -0
  25. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/page.rb +145 -0
  26. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/site.rb +25 -0
  27. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/snippet.rb +66 -0
  28. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/theme_asset.rb +21 -0
  29. data/lib/locomotive/steam/adapters/filesystem/yaml_loaders/translation.rb +72 -0
  30. data/lib/locomotive/steam/adapters/memory.rb +55 -0
  31. data/lib/locomotive/steam/adapters/memory/condition.rb +103 -0
  32. data/lib/locomotive/steam/adapters/memory/dataset.rb +77 -0
  33. data/lib/locomotive/steam/adapters/memory/order.rb +60 -0
  34. data/lib/locomotive/steam/adapters/memory/query.rb +116 -0
  35. data/lib/locomotive/steam/adapters/mongodb.rb +83 -0
  36. data/lib/locomotive/steam/adapters/mongodb/dataset.rb +20 -0
  37. data/lib/locomotive/steam/adapters/mongodb/origin.rb +3 -0
  38. data/lib/locomotive/steam/adapters/mongodb/query.rb +82 -0
  39. data/lib/locomotive/steam/configuration.rb +106 -2
  40. data/lib/locomotive/steam/core_ext.rb +2 -1
  41. data/lib/locomotive/steam/core_ext/hash.rb +31 -19
  42. data/lib/locomotive/steam/core_ext/kernel.rb +14 -0
  43. data/lib/locomotive/steam/core_ext/string.rb +35 -6
  44. data/lib/locomotive/steam/decorators/i18n_decorator.rb +99 -0
  45. data/lib/locomotive/steam/decorators/template_decorator.rb +37 -0
  46. data/lib/locomotive/steam/entities/content_entry.rb +151 -0
  47. data/lib/locomotive/steam/entities/content_type.rb +44 -6
  48. data/lib/locomotive/steam/entities/content_type_field.rb +71 -0
  49. data/lib/locomotive/steam/entities/editable_element.rb +21 -0
  50. data/lib/locomotive/steam/entities/page.rb +48 -127
  51. data/lib/locomotive/steam/entities/site.rb +36 -27
  52. data/lib/locomotive/steam/entities/snippet.rb +20 -0
  53. data/lib/locomotive/steam/entities/theme_asset.rb +9 -0
  54. data/lib/locomotive/steam/entities/translation.rb +15 -0
  55. data/lib/locomotive/steam/initializers.rb +0 -4
  56. data/lib/locomotive/steam/initializers/dragonfly.rb +51 -11
  57. data/lib/locomotive/steam/initializers/i18n.rb +6 -3
  58. data/lib/locomotive/steam/initializers/sprockets.rb +4 -1
  59. data/lib/locomotive/steam/liquid.rb +4 -7
  60. data/lib/locomotive/steam/liquid/drops/base.rb +0 -1
  61. data/lib/locomotive/steam/liquid/drops/content_entry.rb +37 -16
  62. data/lib/locomotive/steam/liquid/drops/content_entry_collection.rb +77 -0
  63. data/lib/locomotive/steam/liquid/drops/content_types.rb +5 -102
  64. data/lib/locomotive/steam/liquid/drops/current_user.rb +23 -0
  65. data/lib/locomotive/steam/liquid/drops/i18n_base.rb +39 -0
  66. data/lib/locomotive/steam/liquid/drops/page.rb +77 -11
  67. data/lib/locomotive/steam/liquid/drops/session_proxy.rb +1 -1
  68. data/lib/locomotive/steam/liquid/drops/site.rb +14 -8
  69. data/lib/locomotive/steam/liquid/drops/upload_file.rb +23 -0
  70. data/lib/locomotive/steam/liquid/errors.rb +3 -9
  71. data/lib/locomotive/steam/liquid/filters/base.rb +62 -0
  72. data/lib/locomotive/steam/liquid/filters/date.rb +85 -61
  73. data/lib/locomotive/steam/liquid/filters/html.rb +30 -115
  74. data/lib/locomotive/steam/liquid/filters/misc.rb +6 -5
  75. data/lib/locomotive/steam/liquid/filters/pagination.rb +55 -0
  76. data/lib/locomotive/steam/liquid/filters/resize.rb +2 -3
  77. data/lib/locomotive/steam/liquid/filters/text.rb +15 -15
  78. data/lib/locomotive/steam/liquid/filters/translate.rb +5 -14
  79. data/lib/locomotive/steam/liquid/patches.rb +29 -23
  80. data/lib/locomotive/steam/liquid/tags/concerns/i18n_page.rb +36 -0
  81. data/lib/locomotive/steam/liquid/tags/concerns/path.rb +114 -0
  82. data/lib/locomotive/steam/liquid/tags/consume.rb +39 -43
  83. data/lib/locomotive/steam/liquid/tags/csrf.rb +21 -12
  84. data/lib/locomotive/steam/liquid/tags/editable.rb +1 -3
  85. data/lib/locomotive/steam/liquid/tags/editable/base.rb +54 -15
  86. data/lib/locomotive/steam/liquid/tags/editable/control.rb +17 -4
  87. data/lib/locomotive/steam/liquid/tags/editable/file.rb +34 -2
  88. data/lib/locomotive/steam/liquid/tags/editable/text.rb +54 -2
  89. data/lib/locomotive/steam/liquid/tags/extends.rb +45 -8
  90. data/lib/locomotive/steam/liquid/tags/fetch_page.rb +38 -0
  91. data/lib/locomotive/steam/liquid/tags/google_analytics.rb +25 -12
  92. data/lib/locomotive/steam/liquid/tags/hybrid.rb +24 -12
  93. data/lib/locomotive/steam/liquid/tags/inherited_block.rb +39 -0
  94. data/lib/locomotive/steam/liquid/tags/inline_editor.rb +14 -4
  95. data/lib/locomotive/steam/liquid/tags/link_to.rb +16 -27
  96. data/lib/locomotive/steam/liquid/tags/locale_switcher.rb +45 -56
  97. data/lib/locomotive/steam/liquid/tags/model_form.rb +72 -0
  98. data/lib/locomotive/steam/liquid/tags/nav.rb +65 -57
  99. data/lib/locomotive/steam/liquid/tags/paginate.rb +79 -47
  100. data/lib/locomotive/steam/liquid/tags/path_to.rb +8 -20
  101. data/lib/locomotive/steam/liquid/tags/seo.rb +8 -8
  102. data/lib/locomotive/steam/liquid/tags/session_assign.rb +6 -8
  103. data/lib/locomotive/steam/liquid/tags/snippet.rb +26 -42
  104. data/lib/locomotive/steam/liquid/tags/with_scope.rb +44 -26
  105. data/lib/locomotive/steam/middlewares.rb +7 -13
  106. data/lib/locomotive/steam/middlewares/default_env.rb +25 -0
  107. data/lib/locomotive/steam/middlewares/dynamic_assets.rb +34 -17
  108. data/lib/locomotive/steam/middlewares/entry_submission.rb +117 -79
  109. data/lib/locomotive/steam/middlewares/favicon.rb +5 -2
  110. data/lib/locomotive/steam/middlewares/helpers.rb +44 -0
  111. data/lib/locomotive/steam/middlewares/locale.rb +25 -17
  112. data/lib/locomotive/steam/middlewares/locale_redirection.rb +62 -0
  113. data/lib/locomotive/steam/middlewares/logging.rb +7 -3
  114. data/lib/locomotive/steam/middlewares/page.rb +17 -48
  115. data/lib/locomotive/steam/middlewares/path.rb +5 -8
  116. data/lib/locomotive/steam/middlewares/renderer.rb +65 -106
  117. data/lib/locomotive/steam/middlewares/robots.rb +20 -0
  118. data/lib/locomotive/steam/middlewares/site.rb +42 -0
  119. data/lib/locomotive/steam/middlewares/sitemap.rb +94 -0
  120. data/lib/locomotive/steam/middlewares/stack_proxy.rb +46 -0
  121. data/lib/locomotive/steam/middlewares/templatized_page.rb +40 -14
  122. data/lib/locomotive/steam/middlewares/threadsafe.rb +65 -0
  123. data/lib/locomotive/steam/middlewares/timezone.rb +10 -6
  124. data/lib/locomotive/steam/models.rb +12 -0
  125. data/lib/locomotive/steam/models/associations/belongs_to.rb +18 -0
  126. data/lib/locomotive/steam/models/associations/embedded.rb +43 -0
  127. data/lib/locomotive/steam/models/associations/has_many.rb +22 -0
  128. data/lib/locomotive/steam/models/associations/many_to_many.rb +22 -0
  129. data/lib/locomotive/steam/models/associations/referenced.rb +48 -0
  130. data/lib/locomotive/steam/models/concerns/validation.rb +58 -0
  131. data/lib/locomotive/steam/models/entity.rb +40 -0
  132. data/lib/locomotive/steam/models/i18n_field.rb +42 -0
  133. data/lib/locomotive/steam/models/mapper.rb +119 -0
  134. data/lib/locomotive/steam/models/pager.rb +53 -0
  135. data/lib/locomotive/steam/models/repository.rb +101 -0
  136. data/lib/locomotive/steam/models/scope.rb +31 -0
  137. data/lib/locomotive/steam/repositories.rb +51 -0
  138. data/lib/locomotive/steam/repositories/content_entry_repository.rb +183 -0
  139. data/lib/locomotive/steam/repositories/content_type_field_repository.rb +50 -0
  140. data/lib/locomotive/steam/repositories/content_type_field_select_option_repository.rb +23 -0
  141. data/lib/locomotive/steam/repositories/content_type_repository.rb +38 -0
  142. data/lib/locomotive/steam/repositories/editable_element_repository.rb +20 -0
  143. data/lib/locomotive/steam/repositories/page_repository.rb +86 -0
  144. data/lib/locomotive/steam/repositories/site_repository.rb +29 -0
  145. data/lib/locomotive/steam/repositories/snippet_repository.rb +19 -0
  146. data/lib/locomotive/steam/repositories/theme_asset_repository.rb +24 -0
  147. data/lib/locomotive/steam/repositories/translation_repository.rb +17 -0
  148. data/lib/locomotive/steam/server.rb +61 -40
  149. data/lib/locomotive/steam/services.rb +120 -1
  150. data/lib/locomotive/steam/services/asset_host_service.rb +51 -0
  151. data/lib/locomotive/steam/services/concerns/decorator.rb +35 -0
  152. data/lib/locomotive/steam/services/csrf_protection_service.rb +13 -0
  153. data/lib/locomotive/steam/services/editable_element_service.rb +19 -0
  154. data/lib/locomotive/steam/services/entry_submission_service.rb +91 -0
  155. data/lib/locomotive/steam/services/external_api_service.rb +55 -0
  156. data/lib/locomotive/steam/services/image_resizer_service.rb +49 -0
  157. data/lib/locomotive/steam/services/liquid_parser_service.rb +23 -0
  158. data/lib/locomotive/steam/services/markdown_service.rb +17 -0
  159. data/lib/locomotive/steam/services/no_cache_service.rb +17 -0
  160. data/lib/locomotive/steam/services/page_finder_service.rb +44 -0
  161. data/lib/locomotive/steam/services/parent_finder_service.rb +23 -0
  162. data/lib/locomotive/steam/services/site_finder_service.rb +13 -0
  163. data/lib/locomotive/steam/services/snippet_finder_service.rb +17 -0
  164. data/lib/locomotive/steam/services/textile_service.rb +17 -0
  165. data/lib/locomotive/steam/services/theme_asset_url_service.rb +43 -0
  166. data/lib/locomotive/steam/services/translator_service.rb +34 -0
  167. data/lib/locomotive/steam/services/url_builder_service.rb +40 -0
  168. data/lib/locomotive/steam/version.rb +1 -1
  169. data/locomotivecms_steam.gemspec +34 -28
  170. data/script/ci/before_build.sh +4 -0
  171. data/spec/fixtures/default/app/content_types/bands.yml +3 -1
  172. data/spec/fixtures/default/app/content_types/events.yml +2 -2
  173. data/spec/fixtures/default/app/views/pages/about_us.liquid.haml +2 -1
  174. data/spec/fixtures/default/app/views/pages/archives.liquid.haml +6 -0
  175. data/spec/fixtures/default/app/views/pages/basic.liquid.haml +1 -0
  176. data/spec/fixtures/default/app/views/pages/contest.liquid.haml +2 -1
  177. data/spec/fixtures/default/app/views/pages/events.fr.liquid +4 -0
  178. data/spec/fixtures/default/app/views/pages/events.liquid.haml +23 -1
  179. data/spec/fixtures/default/app/views/pages/filtered.liquid.haml +16 -5
  180. data/spec/fixtures/default/app/views/pages/grunge_bands.liquid.haml +2 -1
  181. data/spec/fixtures/default/app/views/pages/index.liquid.haml +12 -11
  182. data/spec/fixtures/default/app/views/pages/music.liquid.haml +1 -1
  183. data/spec/fixtures/default/app/views/pages/songs.liquid +6 -0
  184. data/spec/fixtures/default/app/views/pages/songs/song-number-1.liquid.haml +5 -0
  185. data/spec/fixtures/default/app/views/pages/store.liquid +2 -1
  186. data/spec/fixtures/default/app/views/pages/tags.liquid +6 -0
  187. data/spec/fixtures/default/app/views/pages/unlisted_pages.liquid.haml +2 -1
  188. data/spec/fixtures/default/app/views/snippets/song.fr.liquid.haml +1 -1
  189. data/spec/fixtures/default/config/deploy.yml +2 -2
  190. data/spec/fixtures/default/config/site.yml +7 -1
  191. data/spec/fixtures/default/data/bands.yml +3 -0
  192. data/spec/fixtures/mongodb/locomotive_accounts.bson +0 -0
  193. data/spec/fixtures/mongodb/locomotive_accounts.metadata.json +1 -0
  194. data/spec/fixtures/mongodb/locomotive_content_assets.bson +0 -0
  195. data/spec/fixtures/mongodb/locomotive_content_assets.metadata.json +1 -0
  196. data/spec/fixtures/mongodb/locomotive_content_entries.bson +0 -0
  197. data/spec/fixtures/mongodb/locomotive_content_entries.metadata.json +1 -0
  198. data/spec/fixtures/mongodb/locomotive_content_types.bson +0 -0
  199. data/spec/fixtures/mongodb/locomotive_content_types.metadata.json +1 -0
  200. data/spec/fixtures/mongodb/locomotive_pages.bson +0 -0
  201. data/spec/fixtures/mongodb/locomotive_pages.metadata.json +1 -0
  202. data/spec/fixtures/mongodb/locomotive_sites.bson +0 -0
  203. data/spec/fixtures/mongodb/locomotive_sites.metadata.json +1 -0
  204. data/spec/fixtures/mongodb/locomotive_snippets.bson +0 -0
  205. data/spec/fixtures/mongodb/locomotive_snippets.metadata.json +1 -0
  206. data/spec/fixtures/mongodb/locomotive_theme_assets.bson +0 -0
  207. data/spec/fixtures/mongodb/locomotive_theme_assets.metadata.json +1 -0
  208. data/spec/fixtures/mongodb/locomotive_translations.bson +0 -0
  209. data/spec/fixtures/mongodb/locomotive_translations.metadata.json +1 -0
  210. data/spec/fixtures/mongodb/sessions.bson +0 -0
  211. data/spec/fixtures/mongodb/sessions.metadata.json +1 -0
  212. data/spec/fixtures/mongodb/system.indexes.bson +0 -0
  213. data/spec/integration/integration_helper.rb +2 -2
  214. data/spec/integration/liquid/tags/paginate_spec.rb +79 -0
  215. data/spec/integration/repositories/content_entry_repository_spec.rb +94 -0
  216. data/spec/integration/repositories/content_type_repository_spec.rb +69 -0
  217. data/spec/integration/repositories/page_repository_spec.rb +105 -0
  218. data/spec/integration/repositories/site_repository_spec.rb +45 -0
  219. data/spec/integration/repositories/snippet_repository_spec.rb +50 -0
  220. data/spec/integration/repositories/theme_asset_repository_spec.rb +48 -0
  221. data/spec/integration/repositories/translation_repository_spec.rb +50 -0
  222. data/spec/integration/server/assets_spec.rb +60 -0
  223. data/spec/integration/server/basic_spec.rb +100 -100
  224. data/spec/integration/server/contact_form_spec.rb +96 -25
  225. data/spec/integration/server/liquid_spec.rb +19 -41
  226. data/spec/integration/server/nav_spec.rb +49 -0
  227. data/spec/integration/server/session_spec.rb +33 -0
  228. data/spec/integration/server/sitemap_spec.rb +34 -0
  229. data/spec/integration/server/with_scope_spec.rb +28 -2
  230. data/spec/integration/services/external_api_service_spec.rb +20 -0
  231. data/spec/locales/locales_spec.rb +7 -7
  232. data/spec/spec_helper.rb +27 -13
  233. data/spec/support.rb +5 -1
  234. data/spec/support/cache_store.rb +3 -0
  235. data/spec/support/helpers.rb +20 -23
  236. data/spec/support/liquid.rb +29 -0
  237. data/spec/support/pry.rb +4 -0
  238. data/spec/support/time.rb +3 -0
  239. data/spec/unit/adapters/filesystem/yaml_loaders/content_entry_spec.rb +50 -0
  240. data/spec/unit/adapters/filesystem/yaml_loaders/content_type_spec.rb +25 -0
  241. data/spec/unit/adapters/filesystem/yaml_loaders/page_spec.rb +25 -0
  242. data/spec/unit/adapters/filesystem/yaml_loaders/site_spec.rb +19 -0
  243. data/spec/unit/adapters/filesystem/yaml_loaders/snippet_spec.rb +26 -0
  244. data/spec/unit/adapters/filesystem/yaml_loaders/translation_spec.rb +25 -0
  245. data/spec/unit/adapters/filesystem_adapter_spec.rb +53 -0
  246. data/spec/unit/adapters/memory/condition_spec.rb +125 -0
  247. data/spec/unit/adapters/memory/dataset_spec.rb +73 -0
  248. data/spec/unit/adapters/memory/order_spec.rb +67 -0
  249. data/spec/unit/adapters/memory/query_spec.rb +85 -0
  250. data/spec/unit/adapters/memory_adapter_spec.rb +36 -0
  251. data/spec/unit/adapters/mongodb/query_spec.rb +68 -0
  252. data/spec/unit/adapters/mongodb_adapter_spec.rb +17 -0
  253. data/spec/unit/configuration_spec.rb +29 -0
  254. data/spec/unit/core_ext/string_spec.rb +44 -0
  255. data/spec/unit/decorators/i18n_decorator_spec.rb +80 -0
  256. data/spec/unit/entities/content_entry_spec.rb +159 -0
  257. data/spec/unit/entities/content_type_field_spec.rb +67 -0
  258. data/spec/unit/entities/content_type_spec.rb +59 -0
  259. data/spec/unit/entities/page_spec.rb +40 -34
  260. data/spec/unit/entities/site_spec.rb +56 -5
  261. data/spec/unit/initializers/dragonfly_spec.rb +31 -0
  262. data/spec/unit/liquid/drops/content_entry_collection_spec.rb +81 -0
  263. data/spec/unit/liquid/drops/content_entry_spec.rb +99 -0
  264. data/spec/unit/liquid/drops/content_types_spec.rb +25 -0
  265. data/spec/unit/liquid/drops/current_user_spec.rb +45 -0
  266. data/spec/unit/liquid/drops/page_spec.rb +134 -0
  267. data/spec/unit/liquid/drops/session_proxy_spec.rb +13 -0
  268. data/spec/unit/liquid/drops/site_spec.rb +49 -0
  269. data/spec/unit/liquid/filters/date_spec.rb +160 -0
  270. data/spec/unit/liquid/filters/html_spec.rb +263 -0
  271. data/spec/unit/liquid/filters/misc_spec.rb +108 -0
  272. data/spec/unit/liquid/filters/pagination_spec.rb +42 -0
  273. data/spec/unit/liquid/filters/resize_spec.rb +36 -0
  274. data/spec/unit/liquid/filters/text_spec.rb +56 -0
  275. data/spec/unit/liquid/filters/translate_spec.rb +33 -0
  276. data/spec/unit/liquid/patches_spec.rb +50 -0
  277. data/spec/unit/liquid/tags/consume_spec.rb +87 -0
  278. data/spec/unit/liquid/tags/csrf_spec.rb +47 -0
  279. data/spec/unit/liquid/tags/editable/control_spec.rb +109 -0
  280. data/spec/unit/liquid/tags/editable/file_spec.rb +116 -0
  281. data/spec/unit/liquid/tags/editable/text_spec.rb +139 -0
  282. data/spec/unit/liquid/tags/extends_spec.rb +38 -0
  283. data/spec/unit/liquid/tags/fetch_page_spec.rb +39 -0
  284. data/spec/unit/liquid/tags/google_analytics_spec.rb +16 -0
  285. data/spec/unit/liquid/tags/inherited_block_spec.rb +33 -0
  286. data/spec/unit/liquid/tags/link_to_spec.rb +112 -0
  287. data/spec/unit/liquid/tags/locale_switcher_spec.rb +58 -0
  288. data/spec/unit/liquid/tags/model_form_spec.rb +35 -0
  289. data/spec/unit/liquid/tags/nav_spec.rb +184 -111
  290. data/spec/unit/liquid/tags/paginate_spec.rb +131 -0
  291. data/spec/unit/liquid/tags/path_to_spec.rb +100 -0
  292. data/spec/unit/liquid/tags/seo_spec.rb +85 -0
  293. data/spec/unit/liquid/tags/session_assign_spec.rb +51 -0
  294. data/spec/unit/liquid/tags/snippet_spec.rb +42 -0
  295. data/spec/unit/liquid/tags/with_scope_spec.rb +66 -0
  296. data/spec/unit/middlewares/dynamic_assets_spec.rb +25 -0
  297. data/spec/unit/middlewares/locale_redirection_spec.rb +105 -0
  298. data/spec/unit/middlewares/renderer_spec.rb +29 -0
  299. data/spec/unit/middlewares/stack_proxy_spec.rb +67 -0
  300. data/spec/unit/models/mapper_spec.rb +75 -0
  301. data/spec/unit/models/pager_spec.rb +82 -0
  302. data/spec/unit/models/repository_spec.rb +46 -0
  303. data/spec/unit/models/scope_spec.rb +27 -0
  304. data/spec/unit/repositories/content_entry_repository_spec.rb +347 -0
  305. data/spec/unit/repositories/content_type_repository_spec.rb +126 -0
  306. data/spec/unit/repositories/page_repository_spec.rb +365 -0
  307. data/spec/unit/repositories/site_repository_spec.rb +41 -0
  308. data/spec/unit/repositories/snippet_repository_spec.rb +37 -0
  309. data/spec/unit/repositories/theme_asset_repository_spec.rb +35 -0
  310. data/spec/unit/repositories/translation_repository_spec.rb +34 -0
  311. data/spec/unit/services/asset_host_service_spec.rb +79 -0
  312. data/spec/unit/services/entry_submission_service_spec.rb +143 -0
  313. data/spec/unit/services/external_api_service_spec.rb +80 -0
  314. data/spec/unit/services/image_resizer_service_spec.rb +75 -0
  315. data/spec/unit/services/markdown_service_spec.rb +36 -0
  316. data/spec/unit/services/parent_finder_service_spec.rb +41 -0
  317. data/spec/unit/services/textile_service_spec.rb +34 -0
  318. data/spec/unit/services/translator_service_spec.rb +65 -0
  319. data/spec/unit/services/url_builder_service_spec.rb +48 -0
  320. data/spec/unit/services_spec.rb +25 -0
  321. metadata +462 -119
  322. data/example/server.rb +0 -31
  323. data/lib/locomotive/steam/decorators.rb +0 -1
  324. data/lib/locomotive/steam/decorators/page_decorator.rb +0 -50
  325. data/lib/locomotive/steam/exceptions.rb +0 -62
  326. data/lib/locomotive/steam/liquid/scopeable.rb +0 -149
  327. data/lib/locomotive/steam/liquid/tags/editable/long_text.rb +0 -15
  328. data/lib/locomotive/steam/liquid/tags/editable/short_text.rb +0 -20
  329. data/lib/locomotive/steam/liquid/tags/path_helper.rb +0 -98
  330. data/lib/locomotive/steam/loaders/yml/pages_loader.rb +0 -193
  331. data/lib/locomotive/steam/loaders/yml/site_loader.rb +0 -49
  332. data/lib/locomotive/steam/loaders/yml/utils/localized_tree.rb +0 -33
  333. data/lib/locomotive/steam/loaders/yml/utils/yaml_front_matters_template.rb +0 -66
  334. data/lib/locomotive/steam/loaders/yml_loader.rb +0 -33
  335. data/lib/locomotive/steam/mapper.rb +0 -86
  336. data/lib/locomotive/steam/middlewares/base.rb +0 -65
  337. data/lib/locomotive/steam/middlewares/stack.rb +0 -66
  338. data/lib/locomotive/steam/middlewares/static_assets.rb +0 -25
  339. data/lib/locomotive/steam/monkey_patches.rb +0 -3
  340. data/lib/locomotive/steam/monkey_patches/haml.rb +0 -17
  341. data/lib/locomotive/steam/repositories/content_types_repository.rb +0 -14
  342. data/lib/locomotive/steam/repositories/pages_repository.rb +0 -23
  343. data/lib/locomotive/steam/repositories/sites_repository.rb +0 -16
  344. data/lib/locomotive/steam/services/dragonfly.rb +0 -49
  345. data/lib/locomotive/steam/services/external_api.rb +0 -47
  346. data/lib/locomotive/steam/services/markdown.rb +0 -20
  347. data/lib/locomotive/steam/standalone_server.rb +0 -30
  348. data/spec/unit/decorators/page_decorator_spec.rb +0 -55
  349. data/spec/unit/loaders/pages_loader_spec.rb +0 -42
  350. data/spec/unit/loaders/site_loader_spec.rb +0 -21
  351. data/spec/unit/loaders/utils/localized_tree_spec.rb +0 -33
  352. data/spec/unit/loaders/utils/yaml_front_matters_template_spec.rb +0 -39
  353. data/spec/unit/middlewares/base_spec.rb +0 -20
  354. data/spec/unit/middlewares/page_spec.rb +0 -51
  355. data/spec/unit/repositories/pages_spec.rb +0 -11
@@ -0,0 +1,91 @@
1
+ require 'sanitize'
2
+
3
+ module Locomotive
4
+ module Steam
5
+
6
+ class EntrySubmissionService < Struct.new(:content_type_repository, :repository, :locale)
7
+
8
+ include Locomotive::Steam::Services::Concerns::Decorator
9
+
10
+ def submit(slug, attributes = {})
11
+ type = get_type(slug)
12
+
13
+ return nil if type.nil?
14
+
15
+ clean_attributes(attributes)
16
+
17
+ build_entry(type, attributes) do |entry|
18
+ if validate(entry)
19
+ repository.create(entry)
20
+ end
21
+ end
22
+ end
23
+
24
+ def find(type_slug, slug)
25
+ type = get_type(type_slug)
26
+
27
+ return nil if type.nil?
28
+
29
+ i18n_decorate { repository.with(type).by_slug(slug) }
30
+ end
31
+
32
+ def to_json(entry)
33
+ return nil if entry.nil?
34
+
35
+ # default values
36
+ hash = { _slug: entry._slug, content_type_slug: entry.content_type_slug }
37
+
38
+ # dynamic attributes
39
+ entry.content_type.fields.all.each do |field|
40
+ next if %w(belongs_to has_many many_to_many).include?(field.type.to_s)
41
+
42
+ hash[field.name] = entry.send(field.name)
43
+ end
44
+
45
+ # errors
46
+ hash[:errors] = entry.errors.messages unless entry.errors.empty?
47
+
48
+ hash.to_json
49
+ end
50
+
51
+ private
52
+
53
+ def get_type(slug)
54
+ return nil if slug.blank?
55
+
56
+ content_type_repository.by_slug(slug)
57
+ end
58
+
59
+ def build_entry(type, attributes, &block)
60
+ i18n_decorate { repository.with(type).build(attributes) }.tap do |entry|
61
+ yield(entry)
62
+ end
63
+ end
64
+
65
+ def validate(entry)
66
+ # simple validations (existence of values) first
67
+ entry.valid?
68
+
69
+ # check if the entry has unique values for its
70
+ # fields marked as unique are really
71
+ content_type_repository.look_for_unique_fields(entry.content_type).each do |name, _|
72
+ if repository.with(entry.content_type).exists?(name => entry.send(name))
73
+ entry.errors.add(name, :unique)
74
+ end
75
+ end
76
+
77
+ entry.errors.empty?
78
+ end
79
+
80
+ def clean_attributes(attributes)
81
+ attributes.each do |key, value|
82
+ next unless value.is_a?(String)
83
+ attributes[key] = Sanitize.clean(value, Sanitize::Config::BASIC)
84
+ end
85
+ end
86
+
87
+ end
88
+
89
+ end
90
+ end
91
+
@@ -0,0 +1,55 @@
1
+ require 'uri'
2
+ require 'httparty'
3
+
4
+ module Locomotive
5
+ module Steam
6
+ class ExternalAPIService
7
+
8
+ include ::HTTParty
9
+
10
+ def consume(url, options = {})
11
+ options[:base_uri], path = extract_base_uri_and_path(url)
12
+
13
+ options.delete(:format) if options[:format] == 'default'
14
+
15
+ # auth ?
16
+ username, password = options.delete(:username), options.delete(:password)
17
+ options[:basic_auth] = { username: username, password: password } if username
18
+
19
+ perform_request_to(path, options)
20
+ end
21
+
22
+ private
23
+
24
+ def extract_base_uri_and_path(url)
25
+ url = HTTParty.normalize_base_uri(url)
26
+
27
+ uri = URI.parse(url)
28
+ path = uri.request_uri || '/'
29
+ base_uri = "#{uri.scheme}://#{uri.host}"
30
+ base_uri += ":#{uri.port}" if uri.port != 80
31
+
32
+ [base_uri, path]
33
+ end
34
+
35
+ def perform_request_to(path, options)
36
+ # [DEBUG] puts "[WebService] consuming #{path}, #{options.inspect}"
37
+
38
+ # sanitize the options
39
+ options[:format] = options[:format].gsub(/[\'\"]/, '').to_sym if options.has_key?(:format)
40
+ options[:headers] = { 'User-Agent' => 'LocomotiveCMS' } if options[:with_user_agent]
41
+
42
+ response = self.class.get(path, options)
43
+ parsed_response = response.parsed_response
44
+
45
+ if response.code == 200
46
+ HashConverter.to_underscore parsed_response
47
+ else
48
+ Locomotive::Common::Logger.error "[WebService] consumed #{path}, #{options.inspect}, response = #{response.inspect}"
49
+ nil
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,49 @@
1
+ module Locomotive
2
+ module Steam
3
+
4
+ class ImageResizerService < Struct.new(:resizer, :asset_path)
5
+
6
+ IsHTTP = /^https?:\/\//o
7
+
8
+ def resize(source, geometry)
9
+ return nil if disabled? || geometry.blank?
10
+
11
+ if file = fetch_file(source)
12
+ file.thumb(geometry).url
13
+ else
14
+ Locomotive::Common::Logger.error "Unable to resize on the fly: #{source.inspect}"
15
+ nil
16
+ end
17
+ end
18
+
19
+ def disabled?
20
+ resizer.nil? || resizer.plugins[:imagemagick].nil?
21
+ end
22
+
23
+ protected
24
+
25
+ def fetch_file(source)
26
+ url_or_path = get_url_or_path(source)
27
+
28
+ if url_or_path =~ IsHTTP
29
+ resizer.fetch_url(url_or_path)
30
+ else
31
+ path = url_or_path.sub(/(\?.*)$/, '')
32
+ resizer.fetch_file(File.join(asset_path || '', 'public', path))
33
+ end
34
+ end
35
+
36
+ def get_url_or_path(source)
37
+ if source.is_a?(Hash)
38
+ source['url']
39
+ elsif source.respond_to?(:url)
40
+ source.url
41
+ else
42
+ source
43
+ end.strip
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,23 @@
1
+ module Locomotive
2
+ module Steam
3
+
4
+ class LiquidParserService < Struct.new(:parent_finder, :snippet_finder)
5
+
6
+ def parse(page, events_listener = nil)
7
+ _parse(page,
8
+ page: page,
9
+ events_listener: events_listener,
10
+ parent_finder: parent_finder,
11
+ snippet_finder: snippet_finder,
12
+ parser: self)
13
+ end
14
+
15
+ def _parse(object, options = {})
16
+ # Note: the template must not be parsed here
17
+ ::Liquid::Template.parse(object.liquid_source, options)
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ require 'kramdown'
2
+
3
+ module Locomotive
4
+ module Steam
5
+
6
+ class MarkdownService
7
+
8
+ def to_html(text)
9
+ return '' if text.blank?
10
+
11
+ Kramdown::Document.new(text, auto_ids: false).to_html
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Locomotive
2
+ module Steam
3
+
4
+ class NoCacheService
5
+
6
+ def fetch(key, options = {}, &block)
7
+ @last_response = block.call
8
+ end
9
+
10
+ def read(key)
11
+ nil
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,44 @@
1
+ module Locomotive
2
+ module Steam
3
+
4
+ class PageFinderService < Struct.new(:repository)
5
+
6
+ include Locomotive::Steam::Services::Concerns::Decorator
7
+
8
+ def find(path)
9
+ decorate do
10
+ repository.by_fullpath(path)
11
+ end
12
+ end
13
+
14
+ def match(path)
15
+ decorate do
16
+ repository.matching_fullpath(path_combinations(path))
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def path_combinations(path)
23
+ _path_combinations(path.split('/'))
24
+ end
25
+
26
+ def _path_combinations(segments, can_include_template = true)
27
+ return nil if segments.empty?
28
+ segment = segments.shift
29
+
30
+ (can_include_template ? [segment, WILDCARD] : [segment]).map do |_segment|
31
+ if (_combinations = _path_combinations(segments.clone, can_include_template && _segment != WILDCARD))
32
+ [*_combinations].map do |_combination|
33
+ File.join(_segment, _combination)
34
+ end
35
+ else
36
+ [_segment]
37
+ end
38
+ end.flatten
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'page_finder_service'
2
+
3
+ module Locomotive
4
+ module Steam
5
+
6
+ class ParentFinderService < PageFinderService
7
+
8
+ def find(page, fullpath)
9
+ return nil if fullpath.blank?
10
+
11
+ decorate do
12
+ if fullpath.strip == 'parent'
13
+ repository.parent_of(page)
14
+ else
15
+ repository.by_fullpath(fullpath)
16
+ end
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module Locomotive
2
+ module Steam
3
+
4
+ class SiteFinderService < Struct.new(:repository, :request)
5
+
6
+ def find
7
+ repository.by_domain(request.host)
8
+ end
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Locomotive
2
+ module Steam
3
+
4
+ class SnippetFinderService < Struct.new(:repository)
5
+
6
+ include Locomotive::Steam::Services::Concerns::Decorator
7
+
8
+ def find(slug)
9
+ decorate do
10
+ repository.by_slug(slug)
11
+ end
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'RedCloth'
2
+
3
+ module Locomotive
4
+ module Steam
5
+
6
+ class TextileService
7
+
8
+ def to_html(text)
9
+ return '' if text.blank?
10
+
11
+ ::RedCloth.new(text).to_html
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ module Locomotive
2
+ module Steam
3
+
4
+ class ThemeAssetUrlService < Struct.new(:repository, :asset_host, :checksum)
5
+
6
+ def build(path)
7
+ # keep the query string safe
8
+ path.gsub!(/(\?+.+)$/, '')
9
+ query_string = $1
10
+
11
+ # build the url of the theme asset based on the persistence layer
12
+ _url = repository.url_for(path)
13
+
14
+ # get a timestamp only the source url does not include a query string
15
+ timestamp = query_string.blank? ? checksums[path] : nil
16
+
17
+ # prefix by a asset host if given
18
+ url = asset_host ? asset_host.compute(_url, timestamp) : _url
19
+
20
+ query_string ? "#{url}#{query_string}" : url
21
+ end
22
+
23
+ def checksums
24
+ if checksum?
25
+ @checksums ||= fetch_checksums
26
+ else
27
+ {}
28
+ end
29
+ end
30
+
31
+ def checksum?
32
+ !!checksum
33
+ end
34
+
35
+ private
36
+
37
+ def fetch_checksums
38
+ repository.checksums
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,34 @@
1
+ module Locomotive
2
+ module Steam
3
+
4
+ class TranslatorService < Struct.new(:repository, :current_locale)
5
+
6
+ # Return the translation described by a key.
7
+ #
8
+ # @param [ String ] key The key of the translation.
9
+ # @param [ String ] locale The locale we want the translation in
10
+ # @param [ String ] scope If specified, instead of looking in the translations, it will use I18n instead.
11
+ #
12
+ # @return [ String ] the translated text or nil if not found
13
+ #
14
+ def translate(input, locale, scope = nil)
15
+ locale ||= self.current_locale
16
+
17
+ if scope.blank?
18
+ values = repository.by_key(input).try(:values) || {}
19
+
20
+ if translation = values[locale.to_s]
21
+ translation
22
+ else
23
+ Locomotive::Common::Logger.warn "Missing translation '#{input}' for the '#{locale}' locale".yellow
24
+ input
25
+ end
26
+ else
27
+ I18n.t(input, scope: scope.split('.'), locale: locale)
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end