locomotivecms_steam 0.1.1 → 0.1.2.pre.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -2
  3. data/CHANGELOG.md +5 -0
  4. data/Gemfile +10 -2
  5. data/Gemfile.lock +37 -49
  6. data/Rakefile +5 -10
  7. data/example/server.rb +10 -6
  8. data/lib/locomotive/steam.rb +46 -0
  9. data/lib/locomotive/steam/configuration.rb +13 -0
  10. data/lib/locomotive/steam/decorators.rb +1 -0
  11. data/lib/locomotive/steam/decorators/page_decorator.rb +50 -0
  12. data/lib/locomotive/steam/entities/content_type.rb +11 -0
  13. data/lib/locomotive/steam/entities/page.rb +136 -0
  14. data/lib/locomotive/steam/entities/site.rb +30 -0
  15. data/lib/locomotive/steam/initializers/dragonfly.rb +3 -4
  16. data/lib/locomotive/steam/liquid.rb +1 -12
  17. data/lib/locomotive/steam/liquid/drops/base.rb +1 -1
  18. data/lib/locomotive/steam/liquid/drops/content_entry.rb +3 -2
  19. data/lib/locomotive/steam/liquid/drops/content_types.rb +4 -2
  20. data/lib/locomotive/steam/liquid/drops/page.rb +4 -3
  21. data/lib/locomotive/steam/liquid/drops/site.rb +3 -2
  22. data/lib/locomotive/steam/liquid/patches.rb +4 -8
  23. data/lib/locomotive/steam/liquid/tags/nav.rb +19 -17
  24. data/lib/locomotive/steam/loaders/yml/pages_loader.rb +193 -0
  25. data/lib/locomotive/steam/loaders/yml/site_loader.rb +49 -0
  26. data/lib/locomotive/steam/loaders/yml/utils/localized_tree.rb +33 -0
  27. data/lib/locomotive/steam/loaders/yml/utils/yaml_front_matters_template.rb +66 -0
  28. data/lib/locomotive/steam/loaders/yml_loader.rb +33 -0
  29. data/lib/locomotive/steam/mapper.rb +86 -0
  30. data/lib/locomotive/steam/middlewares/base.rb +12 -10
  31. data/lib/locomotive/steam/middlewares/locale.rb +3 -4
  32. data/lib/locomotive/steam/middlewares/page.rb +18 -18
  33. data/lib/locomotive/steam/middlewares/renderer.rb +41 -15
  34. data/lib/locomotive/steam/middlewares/stack.rb +1 -1
  35. data/lib/locomotive/steam/monkey_patches.rb +1 -2
  36. data/lib/locomotive/steam/monkey_patches/haml.rb +1 -1
  37. data/lib/locomotive/steam/repositories/content_types_repository.rb +14 -0
  38. data/lib/locomotive/steam/repositories/pages_repository.rb +23 -0
  39. data/lib/locomotive/steam/repositories/sites_repository.rb +16 -0
  40. data/lib/locomotive/steam/server.rb +14 -11
  41. data/lib/locomotive/steam/services/external_api.rb +2 -1
  42. data/lib/locomotive/steam/services/markdown.rb +3 -12
  43. data/lib/locomotive/steam/standalone_server.rb +2 -2
  44. data/lib/locomotive/steam/version.rb +4 -1
  45. data/locomotivecms_steam.gemspec +11 -5
  46. data/spec/fixtures/default/app/views/pages/basic.liquid.haml +13 -0
  47. data/spec/fixtures/default/config/site.yml +2 -2
  48. data/spec/integration/server/basic_spec.rb +22 -17
  49. data/spec/integration/server/contact_form_spec.rb +1 -1
  50. data/spec/integration/server/liquid_spec.rb +2 -2
  51. data/spec/integration/server/with_scope_spec.rb +2 -2
  52. data/spec/spec_helper.rb +15 -4
  53. data/spec/support/helpers.rb +26 -8
  54. data/spec/unit/decorators/page_decorator_spec.rb +55 -0
  55. data/spec/unit/entities/page_spec.rb +50 -0
  56. data/spec/unit/entities/site_spec.rb +12 -0
  57. data/spec/unit/liquid/tags/nav_spec.rb +159 -0
  58. data/spec/unit/loaders/pages_loader_spec.rb +42 -0
  59. data/spec/unit/loaders/site_loader_spec.rb +21 -0
  60. data/spec/unit/loaders/utils/localized_tree_spec.rb +33 -0
  61. data/spec/unit/loaders/utils/yaml_front_matters_template_spec.rb +39 -0
  62. data/spec/unit/middlewares/base_spec.rb +20 -0
  63. data/spec/unit/middlewares/page_spec.rb +51 -0
  64. data/spec/unit/repositories/pages_spec.rb +11 -0
  65. metadata +128 -23
  66. data/bin/publish +0 -28
  67. data/lib/locomotive/steam/misc.rb +0 -10
  68. data/lib/locomotive/steam/monkey_patches/mounter.rb +0 -54
  69. data/lib/steam.rb +0 -3
@@ -63,4 +63,4 @@ module Locomotive
63
63
 
64
64
  end
65
65
  end
66
- end
66
+ end
@@ -1,4 +1,3 @@
1
1
  # require_relative 'monkey_patches/httparty.rb'
2
2
  # require_relative 'monkey_patches/dragonfly.rb'
3
- require_relative 'monkey_patches/mounter.rb'
4
- require_relative 'monkey_patches/haml.rb'
3
+ require_relative 'monkey_patches/haml.rb'
@@ -14,4 +14,4 @@ module Haml::Filters
14
14
 
15
15
  end
16
16
 
17
- end
17
+ end
@@ -0,0 +1,14 @@
1
+ module Locomotive
2
+ module Steam
3
+ module Repositories
4
+ class ContentTypesRepository
5
+ include Repository
6
+ def [](slug)
7
+ query(:en) do
8
+ where('slug.eq' => slug.to_s)
9
+ end.first
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ module Locomotive
2
+ module Steam
3
+ module Repositories
4
+ class PagesRepository
5
+ include Repository
6
+ attr_accessor :current_locale
7
+
8
+ def [](path)
9
+ query(current_locale) do
10
+ where('fullpath.eq' => path)
11
+ end.first
12
+ end
13
+
14
+ def matching_paths(paths)
15
+ query(current_locale) do
16
+ where('fullpath.in' => paths)
17
+ order_by('position ASC')
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ module Locomotive
2
+ module Steam
3
+ module Repositories
4
+ class SitesRepository
5
+ include Repository
6
+
7
+ def find_by_host(host)
8
+ # TODO multilocales
9
+ query(:en) do
10
+ where('domains.in' => host)
11
+ end.first
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -7,14 +7,13 @@ require_relative 'middlewares'
7
7
  module Locomotive::Steam
8
8
  class Server
9
9
 
10
- attr_reader :reader, :app, :options
10
+ attr_reader :app, :options
11
11
 
12
- def initialize(reader, options = {})
13
- @reader = reader
14
- @options = options
12
+ def initialize(options = {})
13
+ @options = options
15
14
 
16
- stack = Middlewares::Stack.new(options)
17
- @app = stack.create
15
+ stack = Middlewares::Stack.new(options)
16
+ @app = stack.create
18
17
  end
19
18
 
20
19
  def call(env)
@@ -24,7 +23,9 @@ module Locomotive::Steam
24
23
  def _call(env)
25
24
  set_request(env)
26
25
 
27
- set_mounting_point(env)
26
+ set_path(env)
27
+
28
+ fetch_site(env)
28
29
 
29
30
  set_services(env)
30
31
 
@@ -33,20 +34,22 @@ module Locomotive::Steam
33
34
 
34
35
  protected
35
36
 
37
+ def set_path(env)
38
+ env['steam.path'] = options.fetch(:path)
39
+ end
36
40
  def set_request(env)
37
41
  @request = Rack::Request.new(env)
38
42
  env['steam.request'] = @request
39
43
  end
40
44
 
41
- def set_mounting_point(env)
45
+ def fetch_site(env)
42
46
  # one single mounting point per site
43
- @mounting_point = @reader.new_mounting_point(@request.host)
44
- env['steam.mounting_point'] = @reader.mounting_point
47
+ env['steam.site'] = Locomotive::Models[:sites].find_by_host(@request.host)
45
48
  end
46
49
 
47
50
  def set_services(env)
48
51
  env['steam.services'] = {
49
- dragonfly: Locomotive::Steam::Services::Dragonfly.new(@mounting_point.path),
52
+ dragonfly: Locomotive::Steam::Services::Dragonfly.new(options.fetch(:path)),
50
53
  markdown: Locomotive::Steam::Services::Markdown.new,
51
54
  external_api: Locomotive::Steam::Services::ExternalAPI.new
52
55
  }
@@ -1,4 +1,5 @@
1
1
  require 'uri'
2
+ require 'httparty'
2
3
 
3
4
  module Locomotive
4
5
  module Steam
@@ -43,4 +44,4 @@ module Locomotive
43
44
  end
44
45
  end
45
46
  end
46
- end
47
+ end
@@ -1,4 +1,4 @@
1
- require 'redcarpet'
1
+ require 'kramdown'
2
2
 
3
3
  module Locomotive
4
4
  module Steam
@@ -9,18 +9,9 @@ module Locomotive
9
9
  self.class.parser.render(text)
10
10
  end
11
11
 
12
+ # http://kramdown.gettalong.org/options.html
12
13
  def self.parser
13
- @@markdown ||= Redcarpet::Markdown.new Redcarpet::Steam::HTML, {
14
- autolink: true,
15
- fenced_code: true,
16
- generate_toc: true,
17
- gh_blockcode: true,
18
- hard_wrap: true,
19
- no_intraemphasis: true,
20
- strikethrough: true,
21
- tables: true,
22
- xhtml: true
23
- }
14
+ @@markdown ||= Kramdown::Document.new(text).to_html
24
15
  end
25
16
 
26
17
  end
@@ -5,7 +5,7 @@ require_relative 'version'
5
5
  require_relative 'exceptions'
6
6
  require_relative 'server'
7
7
 
8
- require 'locomotive/mounter'
8
+ require 'locomotive/models'
9
9
 
10
10
  module Locomotive
11
11
  module Steam
@@ -27,4 +27,4 @@ module Locomotive
27
27
  end
28
28
  end
29
29
  end
30
- end
30
+ end
@@ -1,5 +1,8 @@
1
+ # http://semver.org/
2
+ # MAJOR.MINOR.PATCH format.
3
+ # 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0
1
4
  module Locomotive
2
5
  module Steam
3
- VERSION = '0.1.1'
6
+ VERSION = '0.1.2-beta'
4
7
  end
5
8
  end
@@ -1,4 +1,4 @@
1
- require_relative 'lib/steam'
1
+ require_relative 'lib/locomotive/steam/version'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'locomotivecms_steam'
@@ -25,17 +25,23 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'rack-test'
26
26
  spec.add_development_dependency 'i18n-spec'
27
27
 
28
+ spec.add_dependency 'httparty', '~> 0.13'
29
+ spec.add_dependency 'httmultiparty', '~> 0.3.10'
28
30
  spec.add_dependency 'rack-cache', '~> 1.1'
29
31
  spec.add_dependency 'moneta', '~> 0.7.20'
30
32
  spec.add_dependency 'sprockets', '~> 2.0'
31
33
  spec.add_dependency 'sprockets-sass', '~> 1.0'
32
34
  spec.add_dependency 'dragonfly', '~> 1.0.3'
33
35
  spec.add_dependency 'will_paginate', '~> 3.0' # TODO: move to kaminari
34
- spec.add_dependency 'redcarpet', '~> 3.1'
36
+ spec.add_dependency 'kramdown', '~> 1.3.3'
37
+ spec.add_dependency 'coffee-script', '~> 2.2.0'
38
+ spec.add_dependency 'haml', '~> 4.0.3'
39
+ spec.add_dependency 'compass', '~> 0.12.2'
35
40
 
36
- spec.add_dependency 'locomotivecms_mounter'
41
+
42
+ spec.add_dependency 'locomotivecms_models', '~> 0.0.1.pre.alpha'
37
43
  spec.add_dependency 'locomotivecms-solid'
38
- spec.add_dependency 'locomotivecms_common', '~> 0.0.1'
44
+ spec.add_dependency 'locomotivecms_common', '~> 0.0.2'
39
45
 
40
- spec.required_ruby_version = '~> 2.0'
46
+ # spec.required_ruby_version = '~> 2.0'
41
47
  end
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: Basic page
3
+ ---
4
+ !!! XML
5
+ !!!
6
+ %html{ :lang => "en" }
7
+ %head
8
+ %meta{ :charset => "utf-8" }
9
+
10
+ %title {{ page.title }}
11
+ %body
12
+ %p
13
+ This is a basic page
@@ -2,7 +2,7 @@ name: Sample website
2
2
 
3
3
  subdomain: sample
4
4
 
5
- domains: ['sample.example.com']
5
+ domains: ['example.org', 'sample.example.com']
6
6
 
7
7
  locales: ['en', 'fr', 'nb']
8
8
 
@@ -12,4 +12,4 @@ seo_title:
12
12
  meta_keywords:
13
13
  en: some meta keywords
14
14
  fr: quelques mots cles
15
- meta_description: some meta description
15
+ meta_description: some meta description
@@ -8,40 +8,45 @@ describe Locomotive::Steam::Server do
8
8
  run_server
9
9
  end
10
10
 
11
- it 'shows the index page' do
11
+ it 'can render the index page', pending: true do
12
+ get '/index'
13
+ last_response.status.should eq(200)
14
+ end
15
+
16
+ it 'shows the index page', pending: true do
12
17
  get '/index'
13
18
  last_response.body.should =~ /Upcoming events/
14
19
  end
15
20
 
16
- it 'shows the 404 page' do
21
+ it 'shows the 404 page', pending: true do
17
22
  get '/void'
18
23
  last_response.status.should eq(404)
19
24
  last_response.body.should =~ /page not found/
20
25
  end
21
26
 
22
- it 'shows the 404 page with 200 status code when its called explicitly' do
27
+ it 'shows the 404 page with 200 status code when its called explicitly', pending: true do
23
28
  get '/404'
24
29
  last_response.status.should eq(200)
25
30
  last_response.body.should =~ /page not found/
26
31
  end
27
32
 
28
- it 'shows content' do
33
+ it 'shows content', pending: true do
29
34
  get '/about-us/jane-doe'
30
35
  last_response.body.should =~ /Lorem ipsum dolor sit amet/
31
36
  end
32
37
 
33
- it 'shows a content type template ' do
38
+ it 'shows a content type template', pending: true do
34
39
  get '/songs/song-number-1'
35
40
  last_response.body.should =~ /Song #1/
36
41
  end
37
42
 
38
- it 'renders a page under a templatized one' do
43
+ it 'renders a page under a templatized one', pending: true do
39
44
  get '/songs/song-number-1/band'
40
45
  last_response.body.should =~ /Song #1/
41
46
  last_response.body.should =~ /Leader: Eddie/
42
47
  end
43
48
 
44
- it 'translates strings' do
49
+ it 'translates strings', pending: true do
45
50
  get '/en'
46
51
  last_response.body.should =~ /Powered by/
47
52
  get '/fr'
@@ -50,18 +55,18 @@ describe Locomotive::Steam::Server do
50
55
  last_response.body.should_not =~ /Powered by/
51
56
  end
52
57
 
53
- it 'provides translation in scopes' do
58
+ it 'provides translation in scopes', pending: true do
54
59
  get '/'
55
60
  last_response.body.should =~ /scoped_translation=.French./
56
61
  end
57
62
 
58
- it 'translates a page with link_to tags inside' do
63
+ it 'translates a page with link_to tags inside', pending: true do
59
64
  get '/fr/notre-musique'
60
65
  last_response.body.should =~ /<h3><a href="\/fr\/songs\/song-number-8">Song #8<\/a><\/h3>/
61
66
  last_response.body.should =~ /Propulsé par/
62
67
  end
63
68
 
64
- it 'returns all the pages' do
69
+ it 'returns all the pages', pending: true do
65
70
  get '/all'
66
71
  last_response.body.should =~ /Home page/
67
72
  last_response.body.should =~ /<li>Home page<\/li>/
@@ -70,7 +75,7 @@ describe Locomotive::Steam::Server do
70
75
  last_response.body.should =~ /<li>A song template<\/li>/
71
76
  end
72
77
 
73
- describe 'snippets' do
78
+ describe 'snippets', pending: true do
74
79
 
75
80
  it 'includes a basic snippet' do
76
81
  get '/'
@@ -84,7 +89,7 @@ describe Locomotive::Steam::Server do
84
89
 
85
90
  end
86
91
 
87
- describe 'nav' do
92
+ describe 'nav', pending: true do
88
93
 
89
94
  subject { get '/all'; last_response.body }
90
95
 
@@ -118,20 +123,20 @@ describe Locomotive::Steam::Server do
118
123
 
119
124
  end
120
125
 
121
- describe 'contents with_scope' do
126
+ describe 'contents with_scope', pending: true do
122
127
  subject { get '/grunge_bands'; last_response.body }
123
128
 
124
129
  it { should match(/Layne/)}
125
130
  it { should_not match(/Peter/) }
126
131
  end
127
132
 
128
- describe "pages with_scope" do
133
+ describe 'pages with_scope', pending: true do
129
134
  subject { get '/unlisted_pages'; last_response.body }
130
135
  it { subject.should match(/Page to test the nav tag/)}
131
136
  it { should_not match(/About Us/)}
132
137
  end
133
138
 
134
- describe 'theme assets' do
139
+ describe 'theme assets', pending: true do
135
140
 
136
141
  subject { get '/all'; last_response.body }
137
142
 
@@ -143,7 +148,7 @@ describe Locomotive::Steam::Server do
143
148
 
144
149
  end
145
150
 
146
- describe 'session' do
151
+ describe 'session', pending: true do
147
152
 
148
153
  subject { get '/contest'; last_response.body }
149
154
 
@@ -161,4 +166,4 @@ describe Locomotive::Steam::Server do
161
166
 
162
167
  end
163
168
 
164
- end
169
+ end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../integration_helper'
2
2
 
3
- describe 'ContactForm' do
3
+ describe 'ContactForm', pending: true do
4
4
 
5
5
  include Rack::Test::Methods
6
6
 
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../integration_helper'
2
2
 
3
- describe Locomotive::Steam::Server do
3
+ describe Locomotive::Steam::Server, pending: true do
4
4
 
5
5
  include Rack::Test::Methods
6
6
 
@@ -84,4 +84,4 @@ describe Locomotive::Steam::Server do
84
84
  end
85
85
  end
86
86
 
87
- end
87
+ end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../integration_helper'
2
2
 
3
- describe 'Complex with_scope conditions' do
3
+ describe 'Complex with_scope conditions', pending: true do
4
4
 
5
5
  include Rack::Test::Methods
6
6
 
@@ -13,4 +13,4 @@ describe 'Complex with_scope conditions' do
13
13
  last_response.body.should =~ /events=1./
14
14
  end
15
15
 
16
- end
16
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,23 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
- require 'common'
5
4
  require 'i18n-spec'
6
5
  require 'coveralls'
7
6
 
8
- require_relative '../lib/steam'
7
+ begin
8
+ require 'pry'
9
+ rescue LoadError
10
+ end
11
+
12
+ require_relative '../lib/locomotive/steam'
9
13
  require_relative 'support'
10
14
 
11
15
  Coveralls.wear!
12
16
 
17
+ Locomotive::Steam.configure do |config|
18
+ config.mode = :test
19
+ end
20
+
13
21
  RSpec.configure do |config|
14
22
  config.include Spec::Helpers
15
23
 
@@ -17,6 +25,9 @@ RSpec.configure do |config|
17
25
  config.run_all_when_everything_filtered = true
18
26
 
19
27
  config.before(:all) { remove_logs }
20
- config.before { reset! }
28
+ config.before do
29
+ reset!
30
+ bootstrap_models
31
+ end
21
32
  config.after { reset! }
22
- end
33
+ end