mascot-rails 0.1.12 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,14 +2,14 @@ require "spec_helper"
2
2
 
3
3
  describe Mascot::Extensions::IndexRequestPath do
4
4
  subject { Mascot::Extensions::IndexRequestPath.new }
5
- let(:site) { Mascot::Site.new(root: "spec/pages") }
6
- let(:resources) { site.resources }
5
+ let(:site) { Mascot::Site.new(root_path: "spec/pages") }
6
+ let(:root) { site.root }
7
7
 
8
8
  context "#process_resources" do
9
- before { subject.process_resources(resources) }
9
+ before { subject.process_resources(root) }
10
10
  it "changes /index.html request_path to /" do
11
11
  # require "pry" ; binding.pry
12
- expect(resources.get_resource("/").request_path).to eql("/")
12
+ expect(root.get_resource("/").request_path).to eql("/")
13
13
  end
14
14
  end
15
15
  end
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Mascot::SiteController, type: :controller do
4
- context "existing templated page" do
4
+ context "templated page" do
5
5
  render_views
6
6
  before { get :show, resource_path: "/time" }
7
7
  let(:resource) { Mascot.configuration.site.get("/time") }
@@ -12,23 +12,23 @@ describe Mascot::SiteController, type: :controller do
12
12
  expect(response.body).to include("<h1>Tick tock, tick tock</h1>")
13
13
  end
14
14
  it "renders layout" do
15
- expect(response.body).to include("<title>Dummy</title>")
15
+ expect(response.body).to include("<title>Test layout</title>")
16
16
  end
17
17
  it "responds with content type" do
18
18
  expect(response.content_type).to eql("text/html")
19
19
  end
20
- context "@_mascot_locals assignment" do
21
- subject { assigns(:_mascot_locals) }
22
- it ":current_page" do
23
- expect(subject[:current_page].asset.path).to eql(resource.asset.path)
20
+ context "helper methods" do
21
+ subject { @controller }
22
+ it "#current_page" do
23
+ expect(subject.send(:current_page).asset.path).to eql(resource.asset.path)
24
24
  end
25
- it ":site" do
26
- expect(subject[:resources]).to eql(Mascot.configuration.resources)
25
+ it "#root" do
26
+ expect(subject.send(:root)).to eql(Mascot.configuration.root)
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
- context "existing static page" do
31
+ context "static page" do
32
32
  render_views
33
33
  before { get :show, resource_path: "/hi" }
34
34
  it "is status 200" do
@@ -8,11 +8,11 @@ describe Mascot::RailsConfiguration do
8
8
  end
9
9
  it "excludes partials if false" do
10
10
  subject.partials = false
11
- expect(subject.resources.to_a.size).to eql(2)
11
+ expect(subject.root.resources.to_a.size).to eql(2)
12
12
  end
13
13
  it "includes partials if true" do
14
14
  subject.partials = true
15
- expect(subject.resources.to_a.size).to eql(3)
15
+ expect(subject.root.resources.to_a.size).to eql(3)
16
16
  end
17
17
  end
18
18
  end
@@ -6,7 +6,7 @@ describe Mascot do
6
6
  context "default configuration" do
7
7
  subject{ Mascot.configuration }
8
8
  it "has site" do
9
- expect(subject.site.root).to eql(Rails.root.join("app/pages"))
9
+ expect(subject.site.root_path).to eql(Rails.root.join("app/pages"))
10
10
  end
11
11
  it "has Rails.application as parent engine" do
12
12
  expect(subject.parent_engine).to eql(Rails.application)
@@ -15,4 +15,7 @@ describe Mascot do
15
15
  expect(subject.routes).to be true
16
16
  end
17
17
  end
18
+ it "prepends Site#root_path to ActionController::Base.view_paths" do
19
+ expect(ActionController::Base.view_paths.first.to_s).to eql(Mascot.configuration.site.root_path.to_s)
20
+ end
18
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mascot-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-18 00:00:00.000000000 Z
11
+ date: 2016-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.12
61
+ version: 0.1.14
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.12
68
+ version: 0.1.14
69
69
  description:
70
70
  email:
71
71
  - bradgessler@gmail.com
@@ -79,7 +79,6 @@ files:
79
79
  - app/helpers/mascot/application_helper.rb
80
80
  - config/routes.rb
81
81
  - lib/mascot-rails.rb
82
- - lib/mascot/action_controller_context.rb
83
82
  - lib/mascot/engine.rb
84
83
  - lib/mascot/extensions/index_request_path.rb
85
84
  - lib/mascot/extensions/partials_remover.rb
@@ -106,6 +105,7 @@ files:
106
105
  - spec/dummy/app/views/layouts/application.html.erb
107
106
  - spec/dummy/app/views/layouts/mailer.html.erb
108
107
  - spec/dummy/app/views/layouts/mailer.text.erb
108
+ - spec/dummy/app/views/layouts/mascot_test_layout.html.erb
109
109
  - spec/dummy/bin/bundle
110
110
  - spec/dummy/bin/rails
111
111
  - spec/dummy/bin/rake
@@ -147,7 +147,6 @@ files:
147
147
  - spec/dummy/public/apple-touch-icon.png
148
148
  - spec/dummy/public/favicon.ico
149
149
  - spec/mascot-rails_spec.rb
150
- - spec/mascot/action_controller_context_spec.rb
151
150
  - spec/mascot/extensions/index_request_path_spec.rb
152
151
  - spec/mascot/extensions/partials_remover_spec.rb
153
152
  - spec/mascot/extensions/rails_request_paths_spec.rb
@@ -203,6 +202,7 @@ test_files:
203
202
  - spec/dummy/app/views/layouts/application.html.erb
204
203
  - spec/dummy/app/views/layouts/mailer.html.erb
205
204
  - spec/dummy/app/views/layouts/mailer.text.erb
205
+ - spec/dummy/app/views/layouts/mascot_test_layout.html.erb
206
206
  - spec/dummy/bin/bundle
207
207
  - spec/dummy/bin/rails
208
208
  - spec/dummy/bin/rake
@@ -244,7 +244,6 @@ test_files:
244
244
  - spec/dummy/public/apple-touch-icon.png
245
245
  - spec/dummy/public/favicon.ico
246
246
  - spec/dummy/Rakefile
247
- - spec/mascot/action_controller_context_spec.rb
248
247
  - spec/mascot/extensions/index_request_path_spec.rb
249
248
  - spec/mascot/extensions/partials_remover_spec.rb
250
249
  - spec/mascot/extensions/rails_request_paths_spec.rb
@@ -1,57 +0,0 @@
1
- module Mascot
2
- # Renders a mascot page via the params path via ActionController.
3
- class ActionControllerContext
4
- attr_reader :controller, :resources
5
-
6
- def initialize(controller: , resources: )
7
- @controller = controller
8
- @resources = resources
9
- end
10
-
11
- # Renders a mascot page, given a path, and accepts parameters like layout
12
- # and locals if the user wants to provide additional context to the rendering
13
- # call.
14
- def render(resource = find_resource, layout: nil, locals: {})
15
- # Users may set the layout from frontmatter.
16
- layout ||= resource.data.fetch("layout", controller_layout)
17
- type = resource.asset.template_extensions.last
18
- locals = locals.merge(current_page: resource, resources: resources)
19
-
20
- # @_mascot_locals variable is used by the wrap_template helper.
21
- controller.instance_variable_set(:@_mascot_locals, locals)
22
- controller.render inline: resource.body,
23
- type: type,
24
- layout: layout,
25
- locals: locals,
26
- content_type: resource.mime_type.to_s
27
- end
28
-
29
- # Mascot::PageNotFoundError is handled in the default Mascot::SiteController
30
- # with an execption that Rails can use to display a 404 error.
31
- def get(path)
32
- resource = resources.get_resource(path)
33
- if resource.nil?
34
- # TODO: Display error in context of Reources class root.
35
- raise Mascot::PageNotFoundError, "No such page: #{path}"
36
- else
37
- resource
38
- end
39
- end
40
-
41
- # Default finder of the resource for the current controller context.###
42
- def find_resource
43
- get controller.params[:resource_path]
44
- end
45
-
46
- private
47
- # Returns the current layout for the inline Mascot renderer.
48
- def controller_layout
49
- layout = controller.send(:_layout)
50
- if layout.instance_of? String
51
- layout
52
- else
53
- File.basename(layout.identifier).split('.').first
54
- end
55
- end
56
- end
57
- end
@@ -1,23 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Mascot::ActionControllerContext do
4
- subject { Mascot::ActionControllerContext.new(controller: controller, resources: resources) }
5
- let(:resources) { Mascot.configuration.resources }
6
- let(:site) { Mascot.configuration.site }
7
- let(:resource) { site.glob("**.erb*").first }
8
- context "#render" do
9
- let(:controller) { instance_double("Controller", render: true, _layout: "application") }
10
- it "calls render" do
11
- expect(controller).to receive(:render).with(inline: resource.body,
12
- type: "erb",
13
- layout: "flipper",
14
- locals: {
15
- current_page: resource,
16
- cat: "in-a-hat",
17
- resources: resources
18
- },
19
- content_type: resource.mime_type.to_s)
20
- subject.render(resource, locals: {cat: "in-a-hat"}, layout: "flipper")
21
- end
22
- end
23
- end