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 +4 -4
- data/app/controllers/mascot/site_controller.rb +39 -5
- data/lib/mascot/engine.rb +3 -0
- data/lib/mascot/extensions/index_request_path.rb +2 -2
- data/lib/mascot/extensions/partials_remover.rb +2 -2
- data/lib/mascot/extensions/rails_request_paths.rb +3 -3
- data/lib/mascot/rails.rb +0 -1
- data/lib/mascot/rails_configuration.rb +6 -6
- data/lib/mascot/route_constraint.rb +3 -3
- data/spec/dummy/app/pages/time.html.erb +1 -0
- data/spec/dummy/app/views/layouts/mascot_test_layout.html.erb +10 -0
- data/spec/dummy/log/production.log +898 -0
- data/spec/dummy/log/test.log +9517 -0
- data/spec/mascot/extensions/index_request_path_spec.rb +4 -4
- data/spec/mascot/mascot_site_controller_spec.rb +9 -9
- data/spec/mascot/rails_configuration_spec.rb +2 -2
- data/spec/mascot-rails_spec.rb +4 -1
- metadata +6 -7
- data/lib/mascot/action_controller_context.rb +0 -57
- data/spec/mascot/action_controller_context_spec.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2e3d24929e65ce95f9706e1b19a9c73bdd7daf7
|
4
|
+
data.tar.gz: 1420175c8e4e062ea24c480cf02224a165bb77d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
11
|
-
@
|
13
|
+
def current_page
|
14
|
+
@_current_page ||= find_resource
|
12
15
|
end
|
16
|
+
helper_method :current_page
|
13
17
|
|
14
|
-
def
|
15
|
-
@
|
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
@@ -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.
|
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(
|
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(
|
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
|
-
|
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(
|
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
|
25
|
-
# Production will cache
|
26
|
-
# the speed at which
|
27
|
-
@
|
28
|
-
@
|
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(
|
5
|
-
@
|
4
|
+
def initialize(root: Mascot.configuration.root)
|
5
|
+
@root = root
|
6
6
|
end
|
7
7
|
|
8
8
|
def matches?(request)
|
9
|
-
!!@
|
9
|
+
!!@root.get(request.path)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|