sitepress-rails 2.0.0.beta3 → 2.0.0.beta4

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
  SHA256:
3
- metadata.gz: 308a11e4d4472d626fb4f81581085c06e6ae98b2334f0540c314fd000be6a6c4
4
- data.tar.gz: 5fcea186abadb31c9ca5d33b392dc6b5b197c7514421f5a07857d253ef34d051
3
+ metadata.gz: 135962bb8c744104c2119d592dc46d33d3bf86d1f0138f9cc8484416770f776d
4
+ data.tar.gz: f9ec3cea5fb45637deef576515ecf039f943087d29c7d6255e2bf98070f7ede5
5
5
  SHA512:
6
- metadata.gz: f1fa2ccd305669f776a95e9723fa4aede892ecfce34801481761278da67eeccaf12e056e07b256a81dbf2d253d09a6810f1bb906b09c54a79723a3e24de56967
7
- data.tar.gz: 1744e9291b6a268a196baaf57a2f208ddbb59b5ce62839b41bda20ee87debcacd7fa30d224a434a6c55878c7fa68ad74e1845cd21f3fbeb05bbc71937847e454
6
+ metadata.gz: 8daefdf6dde16ba78128f812aa1d8fa2e0fc5cf0feeb639844207236d9226231925b7915908d1f31895eb306eabeae54c2c37a5e3e2026cd078b4745754128f7
7
+ data.tar.gz: af534c613a3d31f8dd7e61a7dd131bf01b71cd5915fe9b2ae2876b184ef9f68c715075d40d450fc7e07728c5779150bbbedf5224f07403859ca9fa8a48fb70e5
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ test/dummy/db/*.sqlite3
5
+ test/dummy/db/*.sqlite3-journal
6
+ test/dummy/log/*.log
7
+ test/dummy/tmp/
data/bin/rails ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
6
+ ENGINE_PATH = File.expand_path('../../lib/sitepress-rails/engine', __FILE__)
7
+
8
+ # Set up gems listed in the Gemfile.
9
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
10
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
11
+
12
+ require 'rails/all'
13
+ require 'rails/engine/commands'
@@ -0,0 +1,138 @@
1
+ module Sitepress
2
+ # Serves up Sitepress site pages in a rails application. This is mixed into the
3
+ # Sitepress::SiteController, but may be included into other controllers for static
4
+ # page behavior.
5
+ module SitePages
6
+ # Rails 5 requires a format to be given to the private layout method
7
+ # to return the path to the layout.
8
+ DEFAULT_PAGE_RAILS_FORMATS = [:html].freeze
9
+
10
+ # Default root path of resources.
11
+ ROOT_RESOURCE_PATH = "".freeze
12
+
13
+ extend ActiveSupport::Concern
14
+
15
+ included do
16
+ rescue_from Sitepress::PageNotFoundError, with: :page_not_found
17
+ helper Sitepress::Engine.helpers
18
+ helper_method :current_page, :site
19
+ before_action :append_relative_partial_path, only: :show
20
+ end
21
+
22
+ def show
23
+ render_page current_page
24
+ end
25
+
26
+ protected
27
+ def render_page(page)
28
+ if page.renderable?
29
+ render_text_resource page
30
+ else
31
+ send_binary_resource page
32
+ end
33
+ end
34
+
35
+ def current_page
36
+ @current_page ||= find_resource
37
+ end
38
+
39
+ def site
40
+ Sitepress.site
41
+ end
42
+
43
+ def page_not_found(e)
44
+ raise ActionController::RoutingError, e.message
45
+ end
46
+
47
+ private
48
+ def append_relative_partial_path
49
+ append_view_path current_page.asset.path.dirname
50
+ end
51
+
52
+ def render_text_resource(resource)
53
+ with_sitepress_render_cache do
54
+ render inline: resource.body,
55
+ type: resource.asset.template_extensions.last,
56
+ layout: resource.data.fetch("layout", controller_layout),
57
+ content_type: resource.mime_type.to_s
58
+ end
59
+ end
60
+
61
+ def send_binary_resource(resource)
62
+ send_file resource.asset.path,
63
+ disposition: :inline,
64
+ type: resource.mime_type.to_s
65
+ end
66
+
67
+ # Sitepress::PageNotFoundError is handled in the default Sitepress::SiteController
68
+ # with an execption that Rails can use to display a 404 error.
69
+ def get(path)
70
+ resource = site.resources.get(path)
71
+ if resource.nil?
72
+ # TODO: Display error in context of Reources class root.
73
+ raise Sitepress::PageNotFoundError, "No such page: #{path}"
74
+ else
75
+ resource
76
+ end
77
+ end
78
+
79
+ # Default finder of the resource for the current controller context. If the :resource_path
80
+ # isn't present, then its probably the root path so grab that.
81
+ def find_resource
82
+ get params.fetch(:resource_path, ROOT_RESOURCE_PATH)
83
+ end
84
+
85
+ # When development environments disable the cache, we still want to turn it
86
+ # on during rendering so that view doesn't rebuild the site on each call.
87
+ def with_sitepress_render_cache(&block)
88
+ cache_resources = site.cache_resources
89
+ begin
90
+ site.cache_resources = true
91
+ yield
92
+ ensure
93
+ site.cache_resources = cache_resources
94
+ site.clear_resources_cache unless site.cache_resources
95
+ end
96
+ end
97
+
98
+ # Returns the current layout for the inline Sitepress renderer. This is
99
+ # exposed via some really convoluted private methods inside of the various
100
+ # versions of Rails, so I try my best to hack out the path to the layout below.
101
+ def controller_layout
102
+ private_layout_method = self.method(:_layout)
103
+ layout =
104
+ if Rails.version >= "6"
105
+ private_layout_method.call lookup_context, current_page_rails_formats
106
+ elsif Rails.version >= "5"
107
+ private_layout_method.call current_page_rails_formats
108
+ else
109
+ private_layout_method.call
110
+ end
111
+
112
+ if layout.instance_of? String # Rails 4 and 5 return a string from above.
113
+ layout
114
+ elsif layout # Rails 3 and older return an object that gives us a file name
115
+ File.basename(layout.identifier).split('.').first
116
+ else
117
+ # If none of the conditions are met, then no layout was
118
+ # specified, so nil is returned.
119
+ nil
120
+ end
121
+ end
122
+
123
+ # Rails 5 requires an extension, like `:html`, to resolve a template. This
124
+ # method returns the intersection of the formats Rails supports from Mime::Types
125
+ # and the current page's node formats. If nothing intersects, HTML is returned
126
+ # as a default.
127
+ def current_page_rails_formats
128
+ extensions = current_page.node.formats.extensions
129
+ supported_extensions = extensions & Mime::EXTENSION_LOOKUP.keys
130
+
131
+ if supported_extensions.empty?
132
+ DEFAULT_PAGE_RAILS_FORMATS
133
+ else
134
+ supported_extensions.map?(&:to_sym)
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,7 @@
1
+ module Sitepress
2
+ class SiteController < ActionController::Base
3
+ # Extracted into a module because other controllers may need
4
+ # to be capable of serving Sitepress pages.
5
+ include Sitepress::SitePages
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ Sitepress.configuration.parent_engine.routes.draw do
2
+ if Sitepress.configuration.routes
3
+ constraints Sitepress::RouteConstraint.new do
4
+ get "*resource_path", controller: "sitepress/site", action: "show", as: :page, format: false
5
+ if has_named_route? :root
6
+ Rails.logger.warn 'Sitepress tried to configure `root to: "sitepress/site#show"`, but a root route was already defined.'
7
+ else
8
+ root to: "sitepress/site#show"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require File.expand_path('../../sitepress-core/lib/sitepress/version', __FILE__)
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sitepress-rails"
8
+ spec.version = Sitepress::VERSION
9
+ spec.authors = ["Brad Gessler"]
10
+ spec.email = ["bradgessler@gmail.com"]
11
+
12
+ spec.summary = %q{Sitepress rails integration.}
13
+ spec.homepage = "https://github.com/sitepress/sitepress"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+ spec.test_files = Dir["spec/**/*"]
20
+
21
+ spec.add_development_dependency "rspec-rails"
22
+ spec.add_development_dependency "pry"
23
+ spec.add_development_dependency "rails", ">= 4.0"
24
+
25
+ spec.add_runtime_dependency "sitepress-core", spec.version
26
+
27
+ # We don't need every single rals rependency, so grab the subset here.
28
+ rails_version = ">= 5.0"
29
+ spec.add_dependency "railties", rails_version
30
+ spec.add_dependency "actionpack", rails_version
31
+ spec.add_dependency "sprockets-rails", ">= 2.0.0"
32
+ end
@@ -3049,3 +3049,124 @@ WARNING: Sitepress could not enable Sprockets because it could not find a manife
3049
3049
  WARNING: Sitepress could not enable Sprockets because it could not find a manifest file at "/Users/bradgessler/Projects/sitepress/gems/sitepress-rails/spec/dummy/app/content/assets/config/manifest.js".
3050
3050
  WARNING: Sitepress could not enable Sprockets because it could not find a manifest file at "/Users/bradgessler/Projects/sitepress/gems/sitepress-rails/spec/dummy/app/content/assets/config/manifest.js".
3051
3051
  WARNING: Sitepress could not enable Sprockets because it could not find a manifest file at "/Users/bradgessler/Projects/sitepress/gems/sitepress-rails/spec/dummy/app/content/assets/config/manifest.js".
3052
+ WARNING: Sitepress could not enable Sprockets because it could not find a manifest file at "/Users/bradgessler/Projects/sitepress/gems/sitepress-rails/spec/dummy/app/content/assets/config/manifest.js".
3053
+ Processing by Sitepress::SiteController#show as HTML
3054
+ Parameters: {"resource_path"=>"time"}
3055
+ Rendering layout app/content/layouts/sitepress_test_layout.html.erb
3056
+ Rendering inline template within layouts/sitepress_test_layout
3057
+ Rendered app/content/pages/_stupid.html.erb (Duration: 0.3ms | Allocations: 99)
3058
+ Rendered app/content/pages/partials/_really_stupid.html.erb (Duration: 0.2ms | Allocations: 71)
3059
+ Rendered inline template within layouts/sitepress_test_layout (Duration: 3.6ms | Allocations: 1118)
3060
+ Rendered layout app/content/layouts/sitepress_test_layout.html.erb (Duration: 3.9ms | Allocations: 1303)
3061
+ Completed 200 OK in 14ms (Views: 11.5ms | Allocations: 4225)
3062
+ Processing by Sitepress::SiteController#show as HTML
3063
+ Parameters: {"resource_path"=>"hi"}
3064
+ Rendering inline template
3065
+ Rendered inline template (Duration: 0.1ms | Allocations: 65)
3066
+ Completed 200 OK in 1ms (Views: 0.4ms | Allocations: 588)
3067
+ WARNING: Sitepress could not enable Sprockets because it could not find a manifest file at "/Users/bradgessler/Projects/sitepress/gems/sitepress-rails/spec/dummy/app/content/assets/config/manifest.js".
3068
+ WARNING: Sitepress could not enable Sprockets because it could not find a manifest file at "/Users/bradgessler/Projects/sitepress/gems/sitepress-rails/spec/dummy/app/content/assets/config/manifest.js".
3069
+ WARNING: Sitepress could not enable Sprockets because it could not find a manifest file at "/Users/bradgessler/Projects/sitepress/gems/sitepress-rails/spec/dummy/app/content/assets/config/manifest.js".
3070
+ WARNING: Sitepress could not enable Sprockets because it could not find a manifest file at "/Users/bradgessler/Projects/sitepress/gems/sitepress-rails/spec/dummy/app/content/assets/config/manifest.js".
3071
+ WARNING: Sitepress could not enable Sprockets because it could not find a manifest file at "/Users/bradgessler/Projects/sitepress/gems/sitepress-rails/spec/dummy/app/content/assets/config/manifest.js".
3072
+ Processing by Sitepress::SiteController#show as HTML
3073
+ Parameters: {"resource_path"=>"/non-existent"}
3074
+ Completed 404 Not Found in 1ms (Allocations: 406)
3075
+ Processing by Sitepress::SiteController#show as HTML
3076
+ Parameters: {"resource_path"=>"/time"}
3077
+ Rendering layout app/content/layouts/sitepress_test_layout.html.erb
3078
+ Rendering inline template within layouts/sitepress_test_layout
3079
+ Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary.
3080
+ Rendered app/content/pages/_stupid.html.erb (Duration: 0.2ms | Allocations: 49)
3081
+ Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary.
3082
+ Rendered app/content/pages/partials/_really_stupid.html.erb (Duration: 0.1ms | Allocations: 46)
3083
+ Rendered inline template within layouts/sitepress_test_layout (Duration: 2.8ms | Allocations: 812)
3084
+ Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary.
3085
+ Rendered layout app/content/layouts/sitepress_test_layout.html.erb (Duration: 3.0ms | Allocations: 889)
3086
+ Completed 200 OK in 17ms (Views: 5.2ms | Allocations: 5065)
3087
+ Processing by Sitepress::SiteController#show as HTML
3088
+ Parameters: {"resource_path"=>"/time"}
3089
+ Rendering layout app/content/layouts/sitepress_test_layout.html.erb
3090
+ Rendering inline template within layouts/sitepress_test_layout
3091
+ Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary.
3092
+ Rendered app/content/pages/_stupid.html.erb (Duration: 0.1ms | Allocations: 47)
3093
+ Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary.
3094
+ Rendered app/content/pages/partials/_really_stupid.html.erb (Duration: 0.1ms | Allocations: 46)
3095
+ Rendered inline template within layouts/sitepress_test_layout (Duration: 0.8ms | Allocations: 381)
3096
+ Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary.
3097
+ Rendered layout app/content/layouts/sitepress_test_layout.html.erb (Duration: 1.0ms | Allocations: 458)
3098
+ Completed 200 OK in 3ms (Views: 1.4ms | Allocations: 1682)
3099
+ Processing by Sitepress::SiteController#show as HTML
3100
+ Parameters: {"resource_path"=>"/hi"}
3101
+ Rendering inline template
3102
+ Rendered inline template (Duration: 0.2ms | Allocations: 64)
3103
+ Completed 200 OK in 2ms (Views: 0.7ms | Allocations: 949)
3104
+ Processing by Sitepress::SiteController#show as HTML
3105
+ Parameters: {"resource_path"=>"/hi"}
3106
+ Rendering inline template
3107
+ Rendered inline template (Duration: 0.4ms | Allocations: 64)
3108
+ Completed 200 OK in 3ms (Views: 1.0ms | Allocations: 947)
3109
+ Processing by Sitepress::SiteController#show as HTML
3110
+ Parameters: {"resource_path"=>"/hi"}
3111
+ Rendering inline template
3112
+ Rendered inline template (Duration: 0.3ms | Allocations: 64)
3113
+ Completed 200 OK in 2ms (Views: 0.6ms | Allocations: 947)
3114
+ Processing by Sitepress::SiteController#show as HTML
3115
+ Parameters: {"resource_path"=>"/hi"}
3116
+ Rendering inline template
3117
+ Rendered inline template (Duration: 0.2ms | Allocations: 64)
3118
+ Completed 200 OK in 3ms (Views: 0.7ms | Allocations: 947)
3119
+ Processing by Sitepress::SiteController#show as HTML
3120
+ Parameters: {"resource_path"=>"/time"}
3121
+ Rendering layout app/content/layouts/sitepress_test_layout.html.erb
3122
+ Rendering inline template within layouts/sitepress_test_layout
3123
+ Rendered app/content/pages/_stupid.html.erb (Duration: 0.2ms | Allocations: 71)
3124
+ Rendered app/content/pages/partials/_really_stupid.html.erb (Duration: 0.2ms | Allocations: 69)
3125
+ Rendered inline template within layouts/sitepress_test_layout (Duration: 1.0ms | Allocations: 395)
3126
+ Rendered layout app/content/layouts/sitepress_test_layout.html.erb (Duration: 1.4ms | Allocations: 544)
3127
+ Completed 200 OK in 4ms (Views: 1.9ms | Allocations: 1501)
3128
+ Processing by Sitepress::SiteController#show as HTML
3129
+ Parameters: {"resource_path"=>"/time"}
3130
+ Rendering layout app/content/layouts/sitepress_test_layout.html.erb
3131
+ Rendering inline template within layouts/sitepress_test_layout
3132
+ Rendered app/content/pages/_stupid.html.erb (Duration: 0.0ms | Allocations: 6)
3133
+ Rendered app/content/pages/partials/_really_stupid.html.erb (Duration: 0.0ms | Allocations: 5)
3134
+ Rendered inline template within layouts/sitepress_test_layout (Duration: 0.7ms | Allocations: 266)
3135
+ Rendered layout app/content/layouts/sitepress_test_layout.html.erb (Duration: 0.9ms | Allocations: 309)
3136
+ Completed 200 OK in 3ms (Views: 1.5ms | Allocations: 1266)
3137
+ Processing by Sitepress::SiteController#show as HTML
3138
+ Parameters: {"resource_path"=>"/time"}
3139
+ Rendering layout app/content/layouts/sitepress_test_layout.html.erb
3140
+ Rendering inline template within layouts/sitepress_test_layout
3141
+ Rendered app/content/pages/_stupid.html.erb (Duration: 0.0ms | Allocations: 6)
3142
+ Rendered app/content/pages/partials/_really_stupid.html.erb (Duration: 0.0ms | Allocations: 5)
3143
+ Rendered inline template within layouts/sitepress_test_layout (Duration: 0.6ms | Allocations: 266)
3144
+ Rendered layout app/content/layouts/sitepress_test_layout.html.erb (Duration: 0.8ms | Allocations: 309)
3145
+ Completed 200 OK in 3ms (Views: 1.1ms | Allocations: 1266)
3146
+ Processing by Sitepress::SiteController#show as HTML
3147
+ Parameters: {"resource_path"=>"/time"}
3148
+ Rendering layout app/content/layouts/sitepress_test_layout.html.erb
3149
+ Rendering inline template within layouts/sitepress_test_layout
3150
+ Rendered app/content/pages/_stupid.html.erb (Duration: 0.0ms | Allocations: 6)
3151
+ Rendered app/content/pages/partials/_really_stupid.html.erb (Duration: 0.0ms | Allocations: 5)
3152
+ Rendered inline template within layouts/sitepress_test_layout (Duration: 0.6ms | Allocations: 266)
3153
+ Rendered layout app/content/layouts/sitepress_test_layout.html.erb (Duration: 0.8ms | Allocations: 309)
3154
+ Completed 200 OK in 3ms (Views: 1.2ms | Allocations: 1266)
3155
+ Processing by Sitepress::SiteController#show as HTML
3156
+ Parameters: {"resource_path"=>"/time"}
3157
+ Rendering layout app/content/layouts/sitepress_test_layout.html.erb
3158
+ Rendering inline template within layouts/sitepress_test_layout
3159
+ Rendered app/content/pages/_stupid.html.erb (Duration: 0.0ms | Allocations: 6)
3160
+ Rendered app/content/pages/partials/_really_stupid.html.erb (Duration: 0.0ms | Allocations: 5)
3161
+ Rendered inline template within layouts/sitepress_test_layout (Duration: 0.6ms | Allocations: 269)
3162
+ Rendered layout app/content/layouts/sitepress_test_layout.html.erb (Duration: 0.8ms | Allocations: 312)
3163
+ Completed 200 OK in 3ms (Views: 1.2ms | Allocations: 1272)
3164
+ Processing by Sitepress::SiteController#show as HTML
3165
+ Parameters: {"resource_path"=>"/time"}
3166
+ Rendering layout app/content/layouts/sitepress_test_layout.html.erb
3167
+ Rendering inline template within layouts/sitepress_test_layout
3168
+ Rendered app/content/pages/_stupid.html.erb (Duration: 0.0ms | Allocations: 6)
3169
+ Rendered app/content/pages/partials/_really_stupid.html.erb (Duration: 0.0ms | Allocations: 5)
3170
+ Rendered inline template within layouts/sitepress_test_layout (Duration: 0.7ms | Allocations: 266)
3171
+ Rendered layout app/content/layouts/sitepress_test_layout.html.erb (Duration: 0.9ms | Allocations: 309)
3172
+ Completed 200 OK in 4ms (Views: 1.4ms | Allocations: 1266)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sitepress-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta3
4
+ version: 2.0.0.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 2.0.0.beta3
61
+ version: 2.0.0.beta4
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: 2.0.0.beta3
68
+ version: 2.0.0.beta4
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: railties
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -115,8 +115,10 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
+ - ".gitignore"
118
119
  - README.md
119
120
  - Rakefile
121
+ - bin/rails
120
122
  - lib/sitepress-rails.rb
121
123
  - lib/sitepress/build_paths/directory_index_path.rb
122
124
  - lib/sitepress/build_paths/index_path.rb
@@ -129,6 +131,10 @@ files:
129
131
  - lib/sitepress/renderers/server.rb
130
132
  - lib/sitepress/route_constraint.rb
131
133
  - lib/tasks/sitepress_tasks.rake
134
+ - rails/app/controllers/concerns/sitepress/site_pages.rb
135
+ - rails/app/controllers/sitepress/site_controller.rb
136
+ - rails/config/routes.rb
137
+ - sitepress-rails.gemspec
132
138
  - spec/dummy/Rakefile
133
139
  - spec/dummy/app/assets/config/manifest.js
134
140
  - spec/dummy/app/assets/javascripts/application.js