kiosk 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +25 -0
- data/Rakefile +26 -0
- data/lib/kiosk.rb +58 -0
- data/lib/kiosk/bad_config.rb +5 -0
- data/lib/kiosk/cacheable.rb +6 -0
- data/lib/kiosk/cacheable/connection.rb +102 -0
- data/lib/kiosk/cacheable/resource.rb +90 -0
- data/lib/kiosk/cdn.rb +28 -0
- data/lib/kiosk/claim.rb +12 -0
- data/lib/kiosk/claim/node_claim.rb +44 -0
- data/lib/kiosk/claim/path_claim.rb +11 -0
- data/lib/kiosk/claimed_node.rb +9 -0
- data/lib/kiosk/controller.rb +61 -0
- data/lib/kiosk/document.rb +6 -0
- data/lib/kiosk/indexer.rb +5 -0
- data/lib/kiosk/indexer/adapter.rb +14 -0
- data/lib/kiosk/indexer/adapter/base.rb +10 -0
- data/lib/kiosk/indexer/adapter/thinking_sphinx_adapter.rb +266 -0
- data/lib/kiosk/localizable.rb +5 -0
- data/lib/kiosk/localizable/resource.rb +30 -0
- data/lib/kiosk/localizer.rb +17 -0
- data/lib/kiosk/origin.rb +20 -0
- data/lib/kiosk/prospective_node.rb +18 -0
- data/lib/kiosk/prospector.rb +75 -0
- data/lib/kiosk/resource.rb +313 -0
- data/lib/kiosk/resource_error.rb +5 -0
- data/lib/kiosk/resource_not_found.rb +12 -0
- data/lib/kiosk/resource_uri.rb +82 -0
- data/lib/kiosk/rewrite.rb +13 -0
- data/lib/kiosk/rewrite/cdn_rewrite.rb +9 -0
- data/lib/kiosk/rewrite/node_rewrite.rb +18 -0
- data/lib/kiosk/rewrite/path_rewrite.rb +10 -0
- data/lib/kiosk/rewriter.rb +72 -0
- data/lib/kiosk/searchable.rb +5 -0
- data/lib/kiosk/searchable/resource.rb +15 -0
- data/lib/kiosk/tasks/kiosk.rake +6 -0
- data/lib/kiosk/version.rb +3 -0
- metadata +136 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
module Kiosk
|
2
|
+
module Rewrite
|
3
|
+
autoload :CdnRewrite, 'kiosk/rewrite/cdn_rewrite'
|
4
|
+
autoload :NodeRewrite, 'kiosk/rewrite/node_rewrite'
|
5
|
+
autoload :PathRewrite, 'kiosk/rewrite/path_rewrite'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def new(type = :node, *args, &blk)
|
9
|
+
"kiosk/rewrite/#{type}_rewrite".classify.constantize.new(*args, &blk)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Kiosk
|
2
|
+
module Rewrite
|
3
|
+
class NodeRewrite
|
4
|
+
def initialize(model, &blk)
|
5
|
+
@model = model
|
6
|
+
@proc = blk
|
7
|
+
end
|
8
|
+
|
9
|
+
def matches?(node)
|
10
|
+
node.is_a?(ClaimedNode) && node.resource.is_a?(@model)
|
11
|
+
end
|
12
|
+
|
13
|
+
def evaluate(node)
|
14
|
+
@proc.call(node.resource, node)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
module Kiosk
|
4
|
+
# Rewrites the content of resources.
|
5
|
+
#
|
6
|
+
class Rewriter
|
7
|
+
|
8
|
+
# Creates a new content rewriter.
|
9
|
+
#
|
10
|
+
def initialize
|
11
|
+
@claims = {}
|
12
|
+
@rewrites = []
|
13
|
+
end
|
14
|
+
|
15
|
+
# Adds a +Claim+ to the rewriter. This is typically done indirectly
|
16
|
+
# using +Resource.claims_content+ in each resource model.
|
17
|
+
#
|
18
|
+
# Options:
|
19
|
+
#
|
20
|
+
# - +:priority+: Claims with higher priority (a lower value) take
|
21
|
+
# precedence. Symbols +:high+, +:normal+, +:low+ map to
|
22
|
+
# values -9, 0, and 9 respectively.
|
23
|
+
#
|
24
|
+
def add_claim(claim, options = {})
|
25
|
+
priority = {
|
26
|
+
:high => -9,
|
27
|
+
:normal => 0,
|
28
|
+
:low => 9
|
29
|
+
}.fetch(options[:priority], options[:priority] || 0)
|
30
|
+
|
31
|
+
(@claims[priority] || (@claims[priority] = [])) << claim
|
32
|
+
end
|
33
|
+
|
34
|
+
# Adds a rewrite rule to the rewriter. This is typically done indirectly
|
35
|
+
# using +Controller.rewrite_content_for+ in each controller.
|
36
|
+
#
|
37
|
+
def add_rewrite(rewrite)
|
38
|
+
@rewrites << rewrite
|
39
|
+
end
|
40
|
+
|
41
|
+
# Clears all rewrite rules.
|
42
|
+
#
|
43
|
+
def reset!
|
44
|
+
@rewrites.clear
|
45
|
+
end
|
46
|
+
|
47
|
+
# Runs on claims on the given content, incorporates all controller
|
48
|
+
# rewrites, and returns the resulting content.
|
49
|
+
#
|
50
|
+
def rewrite(content)
|
51
|
+
document = Document.parse(content)
|
52
|
+
|
53
|
+
# Claims are grouped by priority. Process them in order.
|
54
|
+
@claims.keys.sort.each do |k|
|
55
|
+
|
56
|
+
# Iterate of all claims in this priority group.
|
57
|
+
@claims[k].each do |claim|
|
58
|
+
|
59
|
+
# Stake the claim on the content.
|
60
|
+
claim.stake!(document) do |node|
|
61
|
+
# Process all rewrites on the claimed node.
|
62
|
+
@rewrites.each do |rewrite|
|
63
|
+
rewrite.evaluate(node) if rewrite.matches?(node)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
document.to_html
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Kiosk
|
4
|
+
# Provides indexing of content resources for supported search providers. As
|
5
|
+
# of now, only Thinking Sphinx/Sphinx is provided for.
|
6
|
+
#
|
7
|
+
module Searchable::Resource
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
raise BadConfig.new('you must configure an indexer') unless Kiosk.origin.indexer
|
12
|
+
Kiosk.origin.indexer.extend_model(self)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kiosk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel Duvall
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-04-27 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nokogiri
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "1.5"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rails
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 3.0.10
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "2.5"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: shoulda
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id004
|
59
|
+
description: "Kiosk provides APIs for integrating WordPress content into a Ruby application: a base REST model for retrieving content, a caching layer, and a rewriting engine for canonicalizing and contextualizing content elements."
|
60
|
+
email:
|
61
|
+
- dan@mutual.io
|
62
|
+
executables: []
|
63
|
+
|
64
|
+
extensions: []
|
65
|
+
|
66
|
+
extra_rdoc_files: []
|
67
|
+
|
68
|
+
files:
|
69
|
+
- lib/kiosk/bad_config.rb
|
70
|
+
- lib/kiosk/cacheable/connection.rb
|
71
|
+
- lib/kiosk/cacheable/resource.rb
|
72
|
+
- lib/kiosk/cacheable.rb
|
73
|
+
- lib/kiosk/cdn.rb
|
74
|
+
- lib/kiosk/claim/node_claim.rb
|
75
|
+
- lib/kiosk/claim/path_claim.rb
|
76
|
+
- lib/kiosk/claim.rb
|
77
|
+
- lib/kiosk/claimed_node.rb
|
78
|
+
- lib/kiosk/controller.rb
|
79
|
+
- lib/kiosk/document.rb
|
80
|
+
- lib/kiosk/indexer/adapter/base.rb
|
81
|
+
- lib/kiosk/indexer/adapter/thinking_sphinx_adapter.rb
|
82
|
+
- lib/kiosk/indexer/adapter.rb
|
83
|
+
- lib/kiosk/indexer.rb
|
84
|
+
- lib/kiosk/localizable/resource.rb
|
85
|
+
- lib/kiosk/localizable.rb
|
86
|
+
- lib/kiosk/localizer.rb
|
87
|
+
- lib/kiosk/origin.rb
|
88
|
+
- lib/kiosk/prospective_node.rb
|
89
|
+
- lib/kiosk/prospector.rb
|
90
|
+
- lib/kiosk/resource.rb
|
91
|
+
- lib/kiosk/resource_error.rb
|
92
|
+
- lib/kiosk/resource_not_found.rb
|
93
|
+
- lib/kiosk/resource_uri.rb
|
94
|
+
- lib/kiosk/rewrite/cdn_rewrite.rb
|
95
|
+
- lib/kiosk/rewrite/node_rewrite.rb
|
96
|
+
- lib/kiosk/rewrite/path_rewrite.rb
|
97
|
+
- lib/kiosk/rewrite.rb
|
98
|
+
- lib/kiosk/rewriter.rb
|
99
|
+
- lib/kiosk/searchable/resource.rb
|
100
|
+
- lib/kiosk/searchable.rb
|
101
|
+
- lib/kiosk/tasks/kiosk.rake
|
102
|
+
- lib/kiosk/version.rb
|
103
|
+
- lib/kiosk.rb
|
104
|
+
- MIT-LICENSE
|
105
|
+
- Rakefile
|
106
|
+
- Gemfile
|
107
|
+
- README.rdoc
|
108
|
+
homepage: https://github.com/lettersandlight/kiosk
|
109
|
+
licenses: []
|
110
|
+
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: "0"
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: "0"
|
128
|
+
requirements: []
|
129
|
+
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 1.8.23
|
132
|
+
signing_key:
|
133
|
+
specification_version: 3
|
134
|
+
summary: Simple WordPress integration for Ruby applications.
|
135
|
+
test_files: []
|
136
|
+
|