kiosk 0.3.6 → 0.3.7
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.
- data/MIT-LICENSE +1 -1
- data/README.md +162 -0
- data/lib/kiosk/version.rb +1 -1
- metadata +5 -5
- data/README.rdoc +0 -41
data/MIT-LICENSE
CHANGED
data/README.md
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
# Kiosk
|
2
|
+
|
3
|
+
Kiosk provides APIs for integrating WordPress content into a Rails
|
4
|
+
application: a base REST model for retrieving content, a caching layer,
|
5
|
+
and a rewriting engine for canonicalizing and contextualizing content
|
6
|
+
elements.
|
7
|
+
|
8
|
+
This gem was initially developed by [National Novel Writing
|
9
|
+
Month](http://nanowrimo.org) for use in its event website. It has since been
|
10
|
+
released under the MIT license.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
gem install kiosk
|
15
|
+
|
16
|
+
## Configuration
|
17
|
+
|
18
|
+
CMS integration requires a WordPress installation that includes the [JSON
|
19
|
+
API Plugin](http://wordpress.org/extend/plugins/json-api/).
|
20
|
+
|
21
|
+
Once the WP site is up and running, the site endpoint should be specified as
|
22
|
+
the `origin` content server in `config/kiosk.yml` of your Rails application.
|
23
|
+
Different configurations may be specified for each Rails environment, along
|
24
|
+
with a default.
|
25
|
+
|
26
|
+
origins:
|
27
|
+
default:
|
28
|
+
site: 'http://dev.cms.example/site_name'
|
29
|
+
production:
|
30
|
+
site: 'http://cms.example/site_name'
|
31
|
+
|
32
|
+
Localization of content resources depends further on the installation of the
|
33
|
+
[WPML Multilingual CMS](http://wpml.org/) (non-free) and [WPML JSON
|
34
|
+
API](http://wordpress.org/extend/plugins/wpml-json-api/) plugins.
|
35
|
+
|
36
|
+
## Simple Example Usage
|
37
|
+
|
38
|
+
Looking to serve up content on your Rails site at URLs like
|
39
|
+
`/pages/example-page`? The process is just as simple as with any other type of
|
40
|
+
ActiveRecord, Mongoid or other model.
|
41
|
+
|
42
|
+
Define a model class to represent any of your WordPress pages
|
43
|
+
|
44
|
+
class Page < Kiosk::WordPress::Page
|
45
|
+
end
|
46
|
+
|
47
|
+
Set up a route to your pages at `/pages/{id}` and allow the id to work with
|
48
|
+
WordPress page hierarchies (e.g. `/pages/parent-page/child-page`).
|
49
|
+
|
50
|
+
Example::Application.routes.draw do
|
51
|
+
resources :pages, only: [:show], constraints: { id: /.+/ }
|
52
|
+
end
|
53
|
+
|
54
|
+
Define a controller that retrieves a given page.
|
55
|
+
|
56
|
+
class PagesController < ApplicationController
|
57
|
+
def show
|
58
|
+
@page = Page.find_by_slug(params[:id])
|
59
|
+
|
60
|
+
# authorization, etc.
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Define a view that renders the page content. (Note that in this example we're
|
65
|
+
trusting the CMS authors to not inject malicious content. You could easily
|
66
|
+
pass the content through some sort of sanitizer if necessary.)
|
67
|
+
|
68
|
+
<h1><%= @page.title.html_safe %></h1>
|
69
|
+
<%= @page.content.html_safe %>
|
70
|
+
|
71
|
+
At this point, a request to your Rails application at `/pages/example-page`
|
72
|
+
will display your WordPress page! But what about all of those links pointing
|
73
|
+
back to your CMS in the body of the page? There's one final step you have to
|
74
|
+
take to that will integrate your own routes into the page content:
|
75
|
+
canonicalization.
|
76
|
+
|
77
|
+
Canonicalize your page content by defining a Kiosk rewrite in your controller.
|
78
|
+
You could do this in the pages controller itself, but if you plan on
|
79
|
+
exposing CMS resources anywhere else it's usually best to define rewrites in
|
80
|
+
the application controller.
|
81
|
+
|
82
|
+
class ApplicationController
|
83
|
+
include Kiosk::Controller
|
84
|
+
|
85
|
+
before_filter do
|
86
|
+
Kiosk.rewriter.reset!
|
87
|
+
rewrite_paths_for(Page) { |page| page_path(page) }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
That's it! Links in your page content should now point to your Rails page
|
92
|
+
route and, barring images and other attachments, your CMS pages are fully
|
93
|
+
embedded in your application. Now put those content editors to work!
|
94
|
+
|
95
|
+
## How Canonicalization Works
|
96
|
+
|
97
|
+
One of the biggest challenges when implementing Kiosk was writing a
|
98
|
+
canonicalization system that adheres to Rails MVC. This might sound strange
|
99
|
+
until you consider some of the constraints that MVC imposes and the nature of
|
100
|
+
our model data.
|
101
|
+
|
102
|
+
First, our content models are essentially ActiveResource classes that
|
103
|
+
represent WordPress posts, both the metadata _and the post body_, the latter
|
104
|
+
of which we want to re-frame such that it appears to live at the location of
|
105
|
+
our Rails application, not WordPress.
|
106
|
+
|
107
|
+
Second, MVC constrains the model to know nothing about the context in which it
|
108
|
+
may be requested or rendered. That knowledge is for the controller and view,
|
109
|
+
respectively. In other words, to let our content models rewrite links and
|
110
|
+
other elements within the post with our Rails application routes would have
|
111
|
+
broken the MVC rules.
|
112
|
+
|
113
|
+
In order to play nice with the MVC constraint, Kiosk's canonicalization system
|
114
|
+
works by a system of "claims" and rewrites of the HTML served up by WordPress.
|
115
|
+
The model defines the claim, the controller the rewrite.
|
116
|
+
|
117
|
+
1. Content models claim to own certain DOM elements in the HTML of any
|
118
|
+
WordPress resource. For example, a `Page` model could claim to own
|
119
|
+
all `<a>` elements with hrefs that match the WordPress URL for pages.
|
120
|
+
|
121
|
+
2. Controllers define certain rewrite rules that transform DOM elements
|
122
|
+
claimed by a given model. For example, a controller could transform the
|
123
|
+
hrefs of the `<a>` elements claimed by `Page` to point to the
|
124
|
+
application's `/pages/` route, the latter of which the controller has
|
125
|
+
full knowledge of.
|
126
|
+
|
127
|
+
In fact, the above is exactly what we did in our example. If you were to look
|
128
|
+
at the implementation of `Kiosk::WordPress::Page`, you would see something
|
129
|
+
similar to the following.
|
130
|
+
|
131
|
+
claims_path_content(selector: 'a', pattern: '/[^\?]+/')
|
132
|
+
|
133
|
+
For details on how to define more advanced claims, see `Kiosk::Prospector`.
|
134
|
+
|
135
|
+
## Roadmap
|
136
|
+
|
137
|
+
- Refactor off of ActiveResource to a lighter weight RESTful client
|
138
|
+
- Implement framework-agnostic caching adapter
|
139
|
+
- Generalize WordPress integration to pave the way for supporting other CMSs
|
140
|
+
- Factor WordPress specifics out to a separate adapter
|
141
|
+
- More test coverage!
|
142
|
+
|
143
|
+
## Contributions
|
144
|
+
|
145
|
+
Kiosk was developed in a pretty isolated environment for the use cases of
|
146
|
+
National Novel Writing Month. For an open-source project to thrive, it needs
|
147
|
+
contributors. So please, if you find this gem at all useful, please
|
148
|
+
contribute!
|
149
|
+
|
150
|
+
- Fork the project and create a topic branch
|
151
|
+
- Write tests for your new feature or a test that reproduces a bug
|
152
|
+
- Implement your feature or make a bug fix
|
153
|
+
- Commit, push and make a pull request
|
154
|
+
|
155
|
+
## License
|
156
|
+
|
157
|
+
Kiosk is licensed under the terms of the MIT License. See `MIT-LICENSE` for
|
158
|
+
details.
|
159
|
+
|
160
|
+
## Copyright
|
161
|
+
|
162
|
+
Copyright (c) 2013 National Novel Writing Month
|
data/lib/kiosk/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kiosk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-01-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 1.5.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 1.5.4
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rails
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,7 +149,7 @@ files:
|
|
149
149
|
- MIT-LICENSE
|
150
150
|
- Rakefile
|
151
151
|
- Gemfile
|
152
|
-
- README.
|
152
|
+
- README.md
|
153
153
|
homepage: https://github.com/lettersandlight/kiosk
|
154
154
|
licenses: []
|
155
155
|
post_install_message:
|
data/README.rdoc
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
= Kiosk
|
2
|
-
|
3
|
-
Kiosk provides APIs for integrating WordPress content into a Ruby
|
4
|
-
application: a base REST model for retrieving content, a caching layer,
|
5
|
-
and a rewriting engine for canonicalizing and contextualizing content
|
6
|
-
elements.
|
7
|
-
|
8
|
-
This gem was initially developed by the {Office of Letters and
|
9
|
-
Light}[http://lettersandlight.org] for use with {National Novel Writing
|
10
|
-
Month}[http://nanowrimo.org]. It has since been released under the MIT
|
11
|
-
license.
|
12
|
-
|
13
|
-
== Basic Usage Patterns
|
14
|
-
|
15
|
-
(Documentation is forthcoming.)
|
16
|
-
|
17
|
-
== Configuration
|
18
|
-
|
19
|
-
CMS integration requires a WordPress installation that includes the {JSON
|
20
|
-
API Plugin}[http://wordpress.org/extend/plugins/json-api/].
|
21
|
-
|
22
|
-
Once the WP site is up and running, the site endpoint should be specified as
|
23
|
-
the +origin+ content server in `config/kiosk.yml` of your Rails application.
|
24
|
-
Different configurations may be specified for each Rails environment, along
|
25
|
-
with a default.
|
26
|
-
|
27
|
-
origins:
|
28
|
-
default:
|
29
|
-
site: 'http://dev.cms.example/site_name'
|
30
|
-
production:
|
31
|
-
site: 'http://cms.example/site_name'
|
32
|
-
|
33
|
-
Localization of content resources depends further on the installation of the
|
34
|
-
{WPML Multilingual CMS}[http://wpml.org/] (non-free) and {WPML JSON
|
35
|
-
API}[http://wordpress.org/extend/plugins/wpml-json-api/] plugins.
|
36
|
-
|
37
|
-
== Roadmap
|
38
|
-
|
39
|
-
In its current state, Kiosk depends on Rails for caching and ActiveResource as
|
40
|
-
a base REST implementation. These dependencies will be made optional in the
|
41
|
-
near future and alternative implementations made possible.
|