mascot-rails 0.1.12 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af6e9c3364ea71baba94e6f5ef9bb1da5f6b9f1a
4
- data.tar.gz: 2005e26040c90e08b059b47badb31892f9cd13d8
3
+ metadata.gz: b2e3d24929e65ce95f9706e1b19a9c73bdd7daf7
4
+ data.tar.gz: 1420175c8e4e062ea24c480cf02224a165bb77d6
5
5
  SHA512:
6
- metadata.gz: af3841f8d9b0e042e6ef4504fd4032e144ae40473caff36b0265db9ddbc05f8b4b6edc571c5c4055cdfe533ea16a7a7db149691b03d1c1459548e1166fc6c412
7
- data.tar.gz: df370017cb3d2f457720c3a7126eeef85515d066278e6cb05b7bb1685dca3ceb3adb1850da4504e6f710c3c6fbb36bb9fb126e2cfefb9ffeecb92e6a22758707
6
+ metadata.gz: 495e11ae1c807812075cda07c951c7b35fb58fc40be8f5c13fd46d431a55db2b187009c43e0f9589aaaa9aa3d6468fe9200df7e5691698339ab5754573c12658
7
+ data.tar.gz: a68bd323f3c6eff4acd86b0c20e7ee2daeb0a7269712b5d9fd36d80f3bb93ebdd92827bcafe97231e4af65a4d66b875a965090768d3c039c0c3c4e7f4f997ecd
@@ -3,20 +3,54 @@ module Mascot
3
3
  rescue_from Mascot::PageNotFoundError, with: :page_not_found
4
4
 
5
5
  def show
6
- mascot.render mascot.find_resource
6
+ render inline: current_page.body,
7
+ type: current_page.asset.template_extensions.last,
8
+ layout: current_page.data.fetch("layout", controller_layout),
9
+ content_type: current_page.mime_type.to_s
7
10
  end
8
11
 
9
12
  protected
10
- def resources
11
- @_mascot_resources ||= Mascot.configuration.resources
13
+ def current_page
14
+ @_current_page ||= find_resource
12
15
  end
16
+ helper_method :current_page
13
17
 
14
- def mascot
15
- @_mascot_context ||= Mascot::ActionControllerContext.new(controller: self, resources: resources)
18
+ def root
19
+ @_root ||= Mascot.configuration.root
16
20
  end
21
+ helper_method :root
17
22
 
18
23
  def page_not_found(e)
19
24
  raise ActionController::RoutingError, e.message
20
25
  end
26
+
27
+ private
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_resource(path)
32
+ resource = root.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_resource params[:resource_path]
44
+ end
45
+
46
+ # Returns the current layout for the inline Mascot renderer.
47
+ def controller_layout
48
+ layout = self.send(:_layout)
49
+ if layout.instance_of? String
50
+ layout
51
+ else
52
+ File.basename(layout.identifier).split('.').first
53
+ end
54
+ end
21
55
  end
22
56
  end
data/lib/mascot/engine.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  module Mascot
2
2
  class Engine < ::Rails::Engine
3
+ initializer "Add site root to view paths" do |app|
4
+ ActionController::Base.prepend_view_path Mascot.configuration.site.root_path
5
+ end
3
6
  end
4
7
  end
@@ -10,11 +10,11 @@ module Mascot
10
10
  end
11
11
 
12
12
  def process_resources(node)
13
- node.each do |r|
13
+ node.resources.each do |r|
14
14
  asset = r.asset
15
15
  if asset.path.basename.to_s.start_with? @file_name
16
16
  request_path = Pathname.new("/").join(r.request_path).dirname.cleanpath.to_s
17
- node.remove_resource(r)
17
+ node.formats.remove(r)
18
18
  node.add(path: request_path, asset: asset)
19
19
  end
20
20
  end
@@ -5,8 +5,8 @@ module Mascot
5
5
  # Partial rails prefix.
6
6
  PARTIAL_PREFIX = "_".freeze
7
7
 
8
- def process_resources(resources)
9
- resources.each do |r|
8
+ def process_resources(node)
9
+ node.resources.each do |r|
10
10
  r.node.remove if self.class.partial? r.asset.path # Looks like a smiley face, doesn't it?
11
11
  end
12
12
  end
@@ -3,12 +3,12 @@ module Mascot
3
3
  # Removes the file extension from the file so that /hi/there/fun.html can be
4
4
  # resolved via /hi/there/fun.
5
5
  class RailsRequestPaths
6
- def process_resources(resources)
7
- resources.each do |r|
6
+ def process_resources(node)
7
+ node.resources.each do |r|
8
8
  asset = r.asset
9
9
  request_path = r.request_path
10
10
  r.node.remove
11
- resources.add path: self.class.format_path(request_path), asset: asset
11
+ node.add path: self.class.format_path(request_path), asset: asset
12
12
  end
13
13
  end
14
14
 
data/lib/mascot/rails.rb CHANGED
@@ -7,7 +7,6 @@ module Mascot
7
7
  # Rescued by ActionController to display page not found error.
8
8
  PageNotFoundError = Class.new(StandardError)
9
9
 
10
- autoload :ActionControllerContext, "mascot/action_controller_context"
11
10
  autoload :RailsConfiguration, "mascot/rails_configuration"
12
11
  autoload :RouteConstraint, "mascot/route_constraint"
13
12
  module Extensions
@@ -15,17 +15,17 @@ module Mascot
15
15
  end
16
16
 
17
17
  def site
18
- @site ||= Site.new(root: default_root).tap do |site|
18
+ @site ||= Site.new(root_path: default_root).tap do |site|
19
19
  site.resources_pipeline << Extensions::PartialsRemover.new unless partials
20
20
  site.resources_pipeline << Extensions::RailsRequestPaths.new
21
21
  end
22
22
  end
23
23
 
24
- def resources
25
- # Production will cache resources globally. This drastically speeds up
26
- # the speed at which resources are served, but if they change it won't be updated.
27
- @resources = nil unless cache_resources?
28
- @resources ||= site.resources
24
+ def root
25
+ # Production will cache root globally. This drastically speeds up
26
+ # the speed at which root are served, but if they change it won't be updated.
27
+ @root = nil unless cache_resources?
28
+ @root ||= site.root
29
29
  end
30
30
 
31
31
  def cache_resources?
@@ -1,12 +1,12 @@
1
1
  module Mascot
2
2
  # Route constraint for rails routes.rb file.
3
3
  class RouteConstraint
4
- def initialize(resources: Mascot.configuration.resources)
5
- @resources = resources
4
+ def initialize(root: Mascot.configuration.root)
5
+ @root = root
6
6
  end
7
7
 
8
8
  def matches?(request)
9
- !!@resources.get(request.path)
9
+ !!@root.get(request.path)
10
10
  end
11
11
  end
12
12
  end
@@ -1,4 +1,5 @@
1
1
  ---
2
+ layout: mascot_test_layout
2
3
  title: Tick tock, tick tock
3
4
  ---
4
5
 
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Test layout</title>
5
+ <%= csrf_meta_tags %>
6
+ </head>
7
+ <body>
8
+ <%= yield %>
9
+ </body>
10
+ </html>