imprenta 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/README.md +15 -18
- data/lib/imprenta/configuration.rb +10 -3
- data/lib/imprenta/file_rack.rb +18 -4
- data/lib/imprenta/static_server.rb +5 -1
- data/lib/imprenta/version.rb +1 -1
- data/lib/imprenta.rb +2 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: addc2eedab80a43efb3d54cd43969312be95631e
|
4
|
+
data.tar.gz: 6e50491dc5a26982441fd9cd7aad02809b65cb83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d1f1d4b162d4c010c46d98d3686a4eb7dc43775c2afff88b9ee2f4aace1e4af12178a637560de7ee7132c39969eca159ce1da33bb00465d9f182d293f19c769
|
7
|
+
data.tar.gz: 40b4b6e2f02600ac8844ea01c1302bbb511f1d10e8bd6e4914f5cc3401613157bac2b4866d586fa9938b5a7f03deb549d563a4c515a921587fa5eab3af5140d6
|
data/README.md
CHANGED
@@ -27,37 +27,34 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
In the action that you want to cache, use something like the following:
|
29
29
|
|
30
|
-
|
30
|
+
```ruby
|
31
|
+
def publish
|
32
|
+
imprenta_cache_template(template: "path/to/template",
|
33
|
+
layout: 'application',
|
34
|
+
id: 'mytemplateid')
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
+
redirect_to root_path, success: 'Yei page published!'
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
36
40
|
|
37
|
-
redirect_to media_kit_path(@media_kit), notice: 'Media Kit Published'
|
38
|
-
end
|
39
|
-
``
|
40
41
|
|
41
42
|
Then in your routes add the following:
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
``
|
44
|
+
```ruby
|
45
|
+
get 'mystatic-pages/:id', :to => Imprenta.server
|
46
|
+
```
|
48
47
|
|
49
48
|
## Configuration
|
50
49
|
|
51
|
-
Imprenta allows you to customize the Rack server with your own middlewares. By defaut, it
|
50
|
+
Imprenta allows you to customize the Rack Server (Imprenta.server) with your own middlewares. By defaut, it
|
52
51
|
will have loaded a middleware to handle 500,400,401,404, etc.
|
53
52
|
|
54
|
-
|
55
|
-
|
53
|
+
```ruby
|
56
54
|
Imprenta.configure do |config|
|
57
55
|
config.middlewares.use Bugsnag::Rack
|
58
56
|
end
|
59
|
-
|
60
|
-
``
|
57
|
+
```
|
61
58
|
|
62
59
|
## Contributing
|
63
60
|
|
@@ -2,11 +2,12 @@ module Imprenta
|
|
2
2
|
class Configuration
|
3
3
|
# Same configuration pattern that sferik uses in:
|
4
4
|
# https://github.com/sferik/mtgox/blob/master/lib/mtgox/configuration.rb
|
5
|
-
VALID_OPTIONS_KEYS = [:middlewares
|
5
|
+
VALID_OPTIONS_KEYS = [:middlewares,
|
6
|
+
:custom_domain,
|
7
|
+
:development]
|
6
8
|
|
7
9
|
attr_accessor *VALID_OPTIONS_KEYS
|
8
10
|
|
9
|
-
# When this module is extended, set all configuration options to their default values
|
10
11
|
def initialize
|
11
12
|
reset
|
12
13
|
setup_default_middlewares
|
@@ -18,14 +19,20 @@ module Imprenta
|
|
18
19
|
|
19
20
|
def reset
|
20
21
|
self.middlewares = ActionDispatch::MiddlewareStack.new
|
22
|
+
self.development = false
|
23
|
+
self.custom_domain = false
|
21
24
|
end
|
22
25
|
|
23
26
|
def setup_default_middlewares
|
24
|
-
self.middlewares.use ActionDispatch::ShowExceptions, show_exception_app
|
27
|
+
self.middlewares.use ActionDispatch::ShowExceptions, show_exception_app
|
25
28
|
end
|
26
29
|
|
27
30
|
private
|
28
31
|
|
32
|
+
def development?
|
33
|
+
development
|
34
|
+
end
|
35
|
+
|
29
36
|
def show_exception_app
|
30
37
|
ActionDispatch::PublicExceptions.new(Rails.public_path)
|
31
38
|
end
|
data/lib/imprenta/file_rack.rb
CHANGED
@@ -1,13 +1,28 @@
|
|
1
1
|
module Imprenta
|
2
2
|
class FileRack
|
3
|
+
attr_accessor :custom_domain
|
4
|
+
|
5
|
+
def initialize(args = {})
|
6
|
+
@custom_domain = args[:custom_domain]
|
7
|
+
end
|
8
|
+
|
3
9
|
def call(env)
|
4
|
-
|
5
|
-
|
10
|
+
request = ::Rack::Request.new(env)
|
11
|
+
path = custom_domain ? env["SERVER_NAME"] : id_from_env(env)
|
12
|
+
|
13
|
+
raise ::ActionController::RoutingError.exception("Page Not Found") unless path
|
14
|
+
|
15
|
+
file, headers = pick_file_and_headers_for_path(path, request)
|
16
|
+
env.merge!("PATH_INFO" => "/")
|
6
17
|
::Rack::File.new(file, headers).call(env)
|
7
18
|
end
|
8
19
|
|
9
20
|
private
|
10
21
|
|
22
|
+
def id_from_env(env)
|
23
|
+
env["action_dispatch.request.path_parameters"][:id]
|
24
|
+
end
|
25
|
+
|
11
26
|
def get_best_encoding(request)
|
12
27
|
::Rack::Utils.select_best_encoding(%w(gzip identity), request.accept_encoding)
|
13
28
|
end
|
@@ -16,8 +31,7 @@ module Imprenta
|
|
16
31
|
@headers ||= {'Content-Type' => 'text/html' }
|
17
32
|
end
|
18
33
|
|
19
|
-
def pick_file_and_headers_for_path(path,
|
20
|
-
request = ::Rack::Request.new(env)
|
34
|
+
def pick_file_and_headers_for_path(path, request)
|
21
35
|
encoding = get_best_encoding(request)
|
22
36
|
file = "#{Rails.public_path}/imprenta/" + path + '.html'
|
23
37
|
if File.exist?(file)
|
@@ -1,7 +1,11 @@
|
|
1
1
|
module Imprenta
|
2
2
|
class StaticServer
|
3
|
+
|
4
|
+
attr_accessor :custom_domain
|
5
|
+
|
3
6
|
def initialize(args = {})
|
4
7
|
@middleware_stack = args.fetch(:middlewares)
|
8
|
+
@custom_domain = args[:custom_domain]
|
5
9
|
end
|
6
10
|
|
7
11
|
def call(env)
|
@@ -12,7 +16,7 @@ module Imprenta
|
|
12
16
|
private
|
13
17
|
|
14
18
|
def build_app
|
15
|
-
@app ||= @middleware_stack.build(Imprenta::FileRack.new)
|
19
|
+
@app ||= @middleware_stack.build(Imprenta::FileRack.new(custom_domain: custom_domain))
|
16
20
|
end
|
17
21
|
|
18
22
|
end
|
data/lib/imprenta/version.rb
CHANGED
data/lib/imprenta.rb
CHANGED
@@ -10,7 +10,8 @@ module Imprenta
|
|
10
10
|
class << self
|
11
11
|
|
12
12
|
def server
|
13
|
-
Imprenta::StaticServer.new(middlewares: configuration.middlewares
|
13
|
+
Imprenta::StaticServer.new(middlewares: configuration.middlewares,
|
14
|
+
custom_domain: configuration.custom_domain)
|
14
15
|
end
|
15
16
|
|
16
17
|
def configuration
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imprenta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Chacon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,4 +98,3 @@ specification_version: 4
|
|
98
98
|
summary: This gem helps the process of publishing and serving static pages within
|
99
99
|
rails
|
100
100
|
test_files: []
|
101
|
-
has_rdoc:
|