middleman-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +24 -0
  3. data/LICENSE +7 -0
  4. data/Rakefile +14 -0
  5. data/features/json-api.feature +48 -0
  6. data/features/support/env.rb +4 -0
  7. data/features/tilt-formats.feature +54 -0
  8. data/features/xml-api.feature +45 -0
  9. data/fixtures/middleman-app/config.rb +1 -0
  10. data/fixtures/middleman-app/source/images/background.png +0 -0
  11. data/fixtures/middleman-app/source/images/middleman.png +0 -0
  12. data/fixtures/middleman-app/source/index.html.erb +10 -0
  13. data/fixtures/middleman-app/source/javascripts/all.js +1 -0
  14. data/fixtures/middleman-app/source/layouts/layout.erb +19 -0
  15. data/fixtures/middleman-app/source/no-frontmatter.html.erb +1 -0
  16. data/fixtures/middleman-app/source/stylesheets/all.css +55 -0
  17. data/fixtures/middleman-app/source/stylesheets/normalize.css +375 -0
  18. data/fixtures/middleman-app/source/test.html.erb +7 -0
  19. data/fixtures/middleman-app/source/tilt/haml.html.haml +6 -0
  20. data/fixtures/middleman-app/source/tilt/liquid.html.liquid +6 -0
  21. data/fixtures/middleman-app/source/tilt/markdown.html.md +6 -0
  22. data/fixtures/middleman-app/source/tilt/rdoc.html.rdoc +6 -0
  23. data/fixtures/middleman-app/source/tilt/slim.html.slim +7 -0
  24. data/fixtures/middleman-app/source/tilt/textile.html.textile +6 -0
  25. data/lib/middleman-api.rb +7 -0
  26. data/lib/middleman-api/extension.rb +32 -0
  27. data/lib/middleman-api/sitemap.rb +39 -0
  28. data/lib/middleman-api/template.json.erb +1 -0
  29. data/lib/middleman-api/template.rb +25 -0
  30. data/lib/middleman-api/template.xml.erb +1 -0
  31. data/lib/middleman_extension.rb +1 -0
  32. data/middleman-api.gemspec +23 -0
  33. data/readme.md +69 -0
  34. metadata +123 -0
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ # Ignore bundler lock file
2
+ Gemfile.lock
3
+ tmp/*
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "rake", "~> 0.9.2"
7
+ gem "rdoc", "~> 3.9"
8
+ gem "yard", "~> 0.8.0"
9
+ end
10
+
11
+ group :test do
12
+ gem "cucumber", "~> 1.2.0"
13
+ gem "fivemat"
14
+ gem "aruba", "~> 0.4.11"
15
+ gem "rspec", "~> 2.7"
16
+ gem "pry-debugger"
17
+
18
+ # Template Engines
19
+ gem "redcarpet"
20
+ gem "slim"
21
+ gem "RedCloth"
22
+ gem "liquid"
23
+ gem "haml"
24
+ end
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2013 Jordan Andree <jordanandree@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'cucumber/rake/task'
5
+
6
+ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
7
+ t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
8
+ end
9
+
10
+ require 'rake/clean'
11
+
12
+ task :test => ["cucumber"]
13
+
14
+ task :default => :test
@@ -0,0 +1,48 @@
1
+ Feature: JSON API
2
+ Scenario: json frontmatter
3
+ Given the Server is running at "middleman-app"
4
+ When I go to "/test.json"
5
+ Then I should see:
6
+ """
7
+ "meta":{"foo":"bar"}
8
+ """
9
+ And I should see:
10
+ """
11
+ "path":"/test.html"
12
+ """
13
+
14
+ Scenario: json content
15
+ Given the Server is running at "middleman-app"
16
+ When I go to "/test.json"
17
+ Then I should see:
18
+ """
19
+ <h1>Header</h1>\n\n<p>lorem ipsum</p>\n
20
+ """
21
+
22
+ Scenario: template with no front matter
23
+ Given the Server is running at "middleman-app"
24
+ When I go to "/no-frontmatter.json"
25
+ Then I should see:
26
+ """
27
+ <div>No Frontmatter</div>
28
+ """
29
+
30
+ Scenario: built files
31
+ Given a built app at "middleman-app" with flags "--verbose --clean"
32
+ When I cd to "build"
33
+ Then the following files should exist:
34
+ | index.html |
35
+ | index.json |
36
+ | test.html |
37
+ | test.json |
38
+ | tilt/liquid.json |
39
+ | tilt/markdown.html |
40
+ | tilt/markdown.json |
41
+ | tilt/rdoc.html |
42
+ | tilt/rdoc.json |
43
+ | tilt/slim.html |
44
+ | tilt/slim.json |
45
+ | tilt/textile.html |
46
+ | tilt/textile.json |
47
+ | tilt/haml.html |
48
+ | tilt/haml.json |
@@ -0,0 +1,4 @@
1
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
+ require "middleman-core"
3
+ require "middleman-core/step_definitions"
4
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-api')
@@ -0,0 +1,54 @@
1
+ Feature: Tilt Formats
2
+ Scenario: markdown
3
+ Given the Server is running at "middleman-app"
4
+ When I go to "/tilt/markdown.json"
5
+ Then I should see:
6
+ """
7
+ {"meta":{"foo":"bar","baz":"boo"}
8
+ """
9
+ And I should see "<p><strong>Lorem Ipsum</strong></p>"
10
+
11
+ Scenario: textile
12
+ Given the Server is running at "middleman-app"
13
+ When I go to "/tilt/textile.json"
14
+ Then I should see:
15
+ """
16
+ {"meta":{"foo":"bar","baz":"boo"}
17
+ """
18
+ And I should see "<p><strong>Lorem Ipsum</strong></p>"
19
+
20
+ Scenario: slim
21
+ Given the Server is running at "middleman-app"
22
+ When I go to "/tilt/slim.json"
23
+ Then I should see:
24
+ """
25
+ {"meta":{"foo":"bar","baz":"boo"}
26
+ """
27
+ And I should see "<p><strong>Lorem Ipsum</strong></p>"
28
+
29
+ Scenario: liquid
30
+ Given the Server is running at "middleman-app"
31
+ When I go to "/tilt/liquid.json"
32
+ Then I should see:
33
+ """
34
+ {"meta":{"foo":"bar","baz":"boo"}
35
+ """
36
+ And I should see "<p><strong>Lorem Ipsum</strong></p>"
37
+
38
+ Scenario: rdoc
39
+ Given the Server is running at "middleman-app"
40
+ When I go to "/tilt/rdoc.json"
41
+ Then I should see:
42
+ """
43
+ {"meta":{"foo":"bar","baz":"boo"}
44
+ """
45
+ And I should see "<p><strong>Lorem Ipsum</strong></p>"
46
+
47
+ Scenario: haml
48
+ Given the Server is running at "middleman-app"
49
+ When I go to "/tilt/haml.json"
50
+ Then I should see:
51
+ """
52
+ {"meta":{"foo":"bar","baz":"boo"}
53
+ """
54
+ And I should see "<em>Haml</em>"
@@ -0,0 +1,45 @@
1
+ Feature: XML API
2
+ Scenario: xml frontmatter
3
+ Given the Server is running at "middleman-app"
4
+ When I go to "/test.xml"
5
+ Then I should see:
6
+ """
7
+ <meta>
8
+ <foo>bar</foo>
9
+ </meta>
10
+ """
11
+ And I should see:
12
+ """
13
+ <path>/test.html</path>
14
+ """
15
+
16
+ Scenario: xml content
17
+ Given the Server is running at "middleman-app"
18
+ When I go to "/test.xml"
19
+ Then I should see:
20
+ """
21
+ &lt;h1&gt;Header&lt;/h1&gt;
22
+
23
+ &lt;p&gt;lorem ipsum&lt;/p&gt;
24
+ """
25
+
26
+ Scenario: template with no front matter
27
+ Given the Server is running at "middleman-app"
28
+ When I go to "/no-frontmatter.xml"
29
+ Then I should see:
30
+ """
31
+ &lt;div&gt;No Frontmatter&lt;/div&gt;
32
+ """
33
+
34
+ Scenario: built files
35
+ Given a built app at "middleman-app" with flags "--verbose --clean"
36
+ When I cd to "build"
37
+ Then the following files should exist:
38
+ | index.xml |
39
+ | test.xml |
40
+ | tilt/liquid.xml |
41
+ | tilt/markdown.xml |
42
+ | tilt/rdoc.xml |
43
+ | tilt/slim.xml |
44
+ | tilt/textile.xml |
45
+ | tilt/haml.xml |
@@ -0,0 +1 @@
1
+ activate :api
@@ -0,0 +1,10 @@
1
+ ---
2
+ title: Welcome to Middleman
3
+ ---
4
+
5
+ <div class="welcome">
6
+ <h1>Middleman is Watching</h1>
7
+ <p class="doc">
8
+ <%= link_to "Read Online Documentation", "http://middlemanapp.com/" %>
9
+ </p><!-- .doc -->
10
+ </div><!-- .welcome -->
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -0,0 +1,19 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+
6
+ <!-- Always force latest IE rendering engine or request Chrome Frame -->
7
+ <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
8
+
9
+ <!-- Use title if it's in the page YAML frontmatter -->
10
+ <title><%= "The Middleman" %></title>
11
+
12
+ <%= stylesheet_link_tag "normalize", "all" %>
13
+ <%= javascript_include_tag "all" %>
14
+ </head>
15
+
16
+ <body class="<%= page_classes %>">
17
+ <%= yield %>
18
+ </body>
19
+ </html>
@@ -0,0 +1 @@
1
+ <div>No Frontmatter</div>
@@ -0,0 +1,55 @@
1
+ @charset "utf-8";
2
+
3
+ body {
4
+ background: #d4d4d4 url("../images/background.png");
5
+ text-align: center;
6
+ font-family: sans-serif; }
7
+
8
+ h1 {
9
+ color: rgba(0, 0, 0, .3);
10
+ font-weight: bold;
11
+ font-size: 32px;
12
+ letter-spacing: -1px;
13
+ text-transform: uppercase;
14
+ text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
15
+ background: url("../images/middleman.png") no-repeat center 100px;
16
+ padding: 350px 0 10px;
17
+ margin: 0; }
18
+
19
+ .doc {
20
+ font-size: 14px;
21
+ margin: 0; }
22
+ .doc:before,
23
+ .doc:after {
24
+ opacity: .2;
25
+ padding: 6px;
26
+ font-style: normal;
27
+ position: relative;
28
+ content: "•"; }
29
+ .doc a {
30
+ color: rgba(0, 0, 0, 0.3); }
31
+ .doc a:hover {
32
+ color: #666; }
33
+
34
+ .welcome {
35
+ -webkit-animation-name: welcome;
36
+ -webkit-animation-duration: .9s; }
37
+
38
+ @-webkit-keyframes welcome {
39
+ from {
40
+ -webkit-transform: scale(0);
41
+ opacity: 0;
42
+ }
43
+ 50% {
44
+ -webkit-transform: scale(0);
45
+ opacity: 0;
46
+ }
47
+ 82.5% {
48
+ -webkit-transform: scale(1.03);
49
+ -webkit-animation-timing-function: ease-out;
50
+ opacity: 1;
51
+ }
52
+ to {
53
+ -webkit-transform: scale(1);
54
+ }
55
+ }
@@ -0,0 +1,375 @@
1
+ /*! normalize.css v2.0.1 | MIT License | git.io/normalize */
2
+
3
+ /* ==========================================================================
4
+ HTML5 display definitions
5
+ ========================================================================== */
6
+
7
+ /*
8
+ * Corrects `block` display not defined in IE 8/9.
9
+ */
10
+
11
+ article,
12
+ aside,
13
+ details,
14
+ figcaption,
15
+ figure,
16
+ footer,
17
+ header,
18
+ hgroup,
19
+ nav,
20
+ section,
21
+ summary {
22
+ display: block;
23
+ }
24
+
25
+ /*
26
+ * Corrects `inline-block` display not defined in IE 8/9.
27
+ */
28
+
29
+ audio,
30
+ canvas,
31
+ video {
32
+ display: inline-block;
33
+ }
34
+
35
+ /*
36
+ * Prevents modern browsers from displaying `audio` without controls.
37
+ * Remove excess height in iOS 5 devices.
38
+ */
39
+
40
+ audio:not([controls]) {
41
+ display: none;
42
+ height: 0;
43
+ }
44
+
45
+ /*
46
+ * Addresses styling for `hidden` attribute not present in IE 8/9.
47
+ */
48
+
49
+ [hidden] {
50
+ display: none;
51
+ }
52
+
53
+ /* ==========================================================================
54
+ Base
55
+ ========================================================================== */
56
+
57
+ /*
58
+ * 1. Sets default font family to sans-serif.
59
+ * 2. Prevents iOS text size adjust after orientation change, without disabling
60
+ * user zoom.
61
+ */
62
+
63
+ html {
64
+ font-family: sans-serif; /* 1 */
65
+ -webkit-text-size-adjust: 100%; /* 2 */
66
+ -ms-text-size-adjust: 100%; /* 2 */
67
+ }
68
+
69
+ /*
70
+ * Removes default margin.
71
+ */
72
+
73
+ body {
74
+ margin: 0;
75
+ }
76
+
77
+ /* ==========================================================================
78
+ Links
79
+ ========================================================================== */
80
+
81
+ /*
82
+ * Addresses `outline` inconsistency between Chrome and other browsers.
83
+ */
84
+
85
+ a:focus {
86
+ outline: thin dotted;
87
+ }
88
+
89
+ /*
90
+ * Improves readability when focused and also mouse hovered in all browsers.
91
+ */
92
+
93
+ a:active,
94
+ a:hover {
95
+ outline: 0;
96
+ }
97
+
98
+ /* ==========================================================================
99
+ Typography
100
+ ========================================================================== */
101
+
102
+ /*
103
+ * Addresses `h1` font sizes within `section` and `article` in Firefox 4+,
104
+ * Safari 5, and Chrome.
105
+ */
106
+
107
+ h1 {
108
+ font-size: 2em;
109
+ }
110
+
111
+ /*
112
+ * Addresses styling not present in IE 8/9, Safari 5, and Chrome.
113
+ */
114
+
115
+ abbr[title] {
116
+ border-bottom: 1px dotted;
117
+ }
118
+
119
+ /*
120
+ * Addresses style set to `bolder` in Firefox 4+, Safari 5, and Chrome.
121
+ */
122
+
123
+ b,
124
+ strong {
125
+ font-weight: bold;
126
+ }
127
+
128
+ /*
129
+ * Addresses styling not present in Safari 5 and Chrome.
130
+ */
131
+
132
+ dfn {
133
+ font-style: italic;
134
+ }
135
+
136
+ /*
137
+ * Addresses styling not present in IE 8/9.
138
+ */
139
+
140
+ mark {
141
+ background: #ff0;
142
+ color: #000;
143
+ }
144
+
145
+
146
+ /*
147
+ * Corrects font family set oddly in Safari 5 and Chrome.
148
+ */
149
+
150
+ code,
151
+ kbd,
152
+ pre,
153
+ samp {
154
+ font-family: monospace, serif;
155
+ font-size: 1em;
156
+ }
157
+
158
+ /*
159
+ * Improves readability of pre-formatted text in all browsers.
160
+ */
161
+
162
+ pre {
163
+ white-space: pre;
164
+ white-space: pre-wrap;
165
+ word-wrap: break-word;
166
+ }
167
+
168
+ /*
169
+ * Sets consistent quote types.
170
+ */
171
+
172
+ q {
173
+ quotes: "\201C" "\201D" "\2018" "\2019";
174
+ }
175
+
176
+ /*
177
+ * Addresses inconsistent and variable font size in all browsers.
178
+ */
179
+
180
+ small {
181
+ font-size: 80%;
182
+ }
183
+
184
+ /*
185
+ * Prevents `sub` and `sup` affecting `line-height` in all browsers.
186
+ */
187
+
188
+ sub,
189
+ sup {
190
+ font-size: 75%;
191
+ line-height: 0;
192
+ position: relative;
193
+ vertical-align: baseline;
194
+ }
195
+
196
+ sup {
197
+ top: -0.5em;
198
+ }
199
+
200
+ sub {
201
+ bottom: -0.25em;
202
+ }
203
+
204
+ /* ==========================================================================
205
+ Embedded content
206
+ ========================================================================== */
207
+
208
+ /*
209
+ * Removes border when inside `a` element in IE 8/9.
210
+ */
211
+
212
+ img {
213
+ border: 0;
214
+ }
215
+
216
+ /*
217
+ * Corrects overflow displayed oddly in IE 9.
218
+ */
219
+
220
+ svg:not(:root) {
221
+ overflow: hidden;
222
+ }
223
+
224
+ /* ==========================================================================
225
+ Figures
226
+ ========================================================================== */
227
+
228
+ /*
229
+ * Addresses margin not present in IE 8/9 and Safari 5.
230
+ */
231
+
232
+ figure {
233
+ margin: 0;
234
+ }
235
+
236
+ /* ==========================================================================
237
+ Forms
238
+ ========================================================================== */
239
+
240
+ /*
241
+ * Define consistent border, margin, and padding.
242
+ */
243
+
244
+ fieldset {
245
+ border: 1px solid #c0c0c0;
246
+ margin: 0 2px;
247
+ padding: 0.35em 0.625em 0.75em;
248
+ }
249
+
250
+ /*
251
+ * 1. Corrects color not being inherited in IE 8/9.
252
+ * 2. Remove padding so people aren't caught out if they zero out fieldsets.
253
+ */
254
+
255
+ legend {
256
+ border: 0; /* 1 */
257
+ padding: 0; /* 2 */
258
+ }
259
+
260
+ /*
261
+ * 1. Corrects font family not being inherited in all browsers.
262
+ * 2. Corrects font size not being inherited in all browsers.
263
+ * 3. Addresses margins set differently in Firefox 4+, Safari 5, and Chrome
264
+ */
265
+
266
+ button,
267
+ input,
268
+ select,
269
+ textarea {
270
+ font-family: inherit; /* 1 */
271
+ font-size: 100%; /* 2 */
272
+ margin: 0; /* 3 */
273
+ }
274
+
275
+ /*
276
+ * Addresses Firefox 4+ setting `line-height` on `input` using `!important` in
277
+ * the UA stylesheet.
278
+ */
279
+
280
+ button,
281
+ input {
282
+ line-height: normal;
283
+ }
284
+
285
+ /*
286
+ * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
287
+ * and `video` controls.
288
+ * 2. Corrects inability to style clickable `input` types in iOS.
289
+ * 3. Improves usability and consistency of cursor style between image-type
290
+ * `input` and others.
291
+ */
292
+
293
+ button,
294
+ html input[type="button"], /* 1 */
295
+ input[type="reset"],
296
+ input[type="submit"] {
297
+ -webkit-appearance: button; /* 2 */
298
+ cursor: pointer; /* 3 */
299
+ }
300
+
301
+ /*
302
+ * Re-set default cursor for disabled elements.
303
+ */
304
+
305
+ button[disabled],
306
+ input[disabled] {
307
+ cursor: default;
308
+ }
309
+
310
+ /*
311
+ * 1. Addresses box sizing set to `content-box` in IE 8/9.
312
+ * 2. Removes excess padding in IE 8/9.
313
+ */
314
+
315
+ input[type="checkbox"],
316
+ input[type="radio"] {
317
+ box-sizing: border-box; /* 1 */
318
+ padding: 0; /* 2 */
319
+ }
320
+
321
+ /*
322
+ * 1. Addresses `appearance` set to `searchfield` in Safari 5 and Chrome.
323
+ * 2. Addresses `box-sizing` set to `border-box` in Safari 5 and Chrome
324
+ * (include `-moz` to future-proof).
325
+ */
326
+
327
+ input[type="search"] {
328
+ -webkit-appearance: textfield; /* 1 */
329
+ -moz-box-sizing: content-box;
330
+ -webkit-box-sizing: content-box; /* 2 */
331
+ box-sizing: content-box;
332
+ }
333
+
334
+ /*
335
+ * Removes inner padding and search cancel button in Safari 5 and Chrome
336
+ * on OS X.
337
+ */
338
+
339
+ input[type="search"]::-webkit-search-cancel-button,
340
+ input[type="search"]::-webkit-search-decoration {
341
+ -webkit-appearance: none;
342
+ }
343
+
344
+ /*
345
+ * Removes inner padding and border in Firefox 4+.
346
+ */
347
+
348
+ button::-moz-focus-inner,
349
+ input::-moz-focus-inner {
350
+ border: 0;
351
+ padding: 0;
352
+ }
353
+
354
+ /*
355
+ * 1. Removes default vertical scrollbar in IE 8/9.
356
+ * 2. Improves readability and alignment in all browsers.
357
+ */
358
+
359
+ textarea {
360
+ overflow: auto; /* 1 */
361
+ vertical-align: top; /* 2 */
362
+ }
363
+
364
+ /* ==========================================================================
365
+ Tables
366
+ ========================================================================== */
367
+
368
+ /*
369
+ * Remove most spacing between table cells.
370
+ */
371
+
372
+ table {
373
+ border-collapse: collapse;
374
+ border-spacing: 0;
375
+ }
@@ -0,0 +1,7 @@
1
+ ---
2
+ foo: bar
3
+ ---
4
+
5
+ <h1>Header</h1>
6
+
7
+ <p>lorem ipsum</p>
@@ -0,0 +1,6 @@
1
+ ---
2
+ foo: bar
3
+ baz: boo
4
+ ---
5
+
6
+ %em Haml
@@ -0,0 +1,6 @@
1
+ ---
2
+ foo: bar
3
+ baz: boo
4
+ ---
5
+
6
+ <p><strong>Lorem Ipsum</strong></p>
@@ -0,0 +1,6 @@
1
+ ---
2
+ foo: bar
3
+ baz: boo
4
+ ---
5
+
6
+ **Lorem Ipsum**
@@ -0,0 +1,6 @@
1
+ ---
2
+ foo: bar
3
+ baz: boo
4
+ ---
5
+
6
+ <b>Lorem Ipsum</b>
@@ -0,0 +1,7 @@
1
+ ---
2
+ foo: bar
3
+ baz: boo
4
+ ---
5
+
6
+ p
7
+ strong Lorem Ipsum
@@ -0,0 +1,6 @@
1
+ ---
2
+ foo: bar
3
+ baz: boo
4
+ ---
5
+
6
+ *Lorem Ipsum*
@@ -0,0 +1,7 @@
1
+ require "middleman-core"
2
+ require "middleman-more"
3
+
4
+ Middleman::Extensions.register(:api) do
5
+ require "middleman-api/extension"
6
+ Middleman::Api
7
+ end
@@ -0,0 +1,32 @@
1
+ require "middleman-api/template"
2
+ require "middleman-api/sitemap"
3
+
4
+ # Extension namespace
5
+ module Middleman::Api
6
+ class << self
7
+
8
+ # Called when extension is activated
9
+ def registered(app, options={})
10
+ # Add class methods to context
11
+ app.send :include, ClassMethods
12
+
13
+ app.after_configuration do
14
+ # Register json.erb template
15
+ sitemap.register_resource_list_manipulator(:middleman_api_template, Middleman::Api::Template.new(self), false)
16
+
17
+ # Register resource manipulator for pages with frontmatter
18
+ sitemap.register_resource_list_manipulator(:middleman_api, Middleman::Api::Sitemap.new(self), false)
19
+ end
20
+ end
21
+
22
+ alias :included :registered
23
+
24
+ module ClassMethods
25
+ # @return [Hash]
26
+ def api_formats
27
+ [:json, :xml]
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,39 @@
1
+ require "active_support/core_ext"
2
+
3
+ module Middleman::Api
4
+ class Sitemap
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ # Update the main sitemap resource list
10
+ # @return [void]
11
+ def manipulate_resource_list(resources)
12
+ proxies = []
13
+ resources.each do |resource|
14
+ ext = resource.ext.gsub('.','').to_sym
15
+ if resource.template? && !(@app.api_formats.include?(ext))
16
+ @app.api_formats.each do |format|
17
+ path = "#{resource.path.split('.').first}.#{format}"
18
+ proxy = ::Middleman::Sitemap::Resource.new(@app.sitemap, path)
19
+ proxy.proxy_to "api.#{format}"
20
+ proxy.add_metadata locals: template_data(resource, format)
21
+ proxy.add_metadata options: { layout: false }
22
+ proxies << proxy
23
+ end
24
+ end
25
+ end
26
+ proxies + resources
27
+ end
28
+
29
+ # Resource data hash
30
+ # @return [Hash] resource data to be parsed into json
31
+ def template_data(resource, format)
32
+ data = {}
33
+ data[:meta] = resource.data
34
+ data[:path] = resource.url
35
+ data[:content] = resource.render
36
+ { data: data.send("to_#{format}") }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1 @@
1
+ <%= data %>
@@ -0,0 +1,25 @@
1
+ module Middleman::Api
2
+ class Template
3
+ def initialize(app)
4
+ @app = app
5
+ @app.after_configuration do
6
+ api_formats.each {|f| ignore "api.#{f}"}
7
+ end
8
+ end
9
+
10
+ # Update the main sitemap resource list
11
+ # @return [void]
12
+ def manipulate_resource_list(resources)
13
+ templates = []
14
+ @app.api_formats.each do |f|
15
+ templates << ::Middleman::Sitemap::Resource.new(@app.sitemap, "api.#{f}", template(f))
16
+ end
17
+ resources + templates
18
+ end
19
+
20
+ private
21
+ def template(format)
22
+ File.expand_path "../template.#{format}.erb", __FILE__
23
+ end
24
+ end
25
+ end
@@ -0,0 +1 @@
1
+ <%= data %>
@@ -0,0 +1 @@
1
+ require "middleman-api"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "middleman-api"
6
+ s.version = "0.1.0"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["jordanandree"]
9
+ s.email = ["jordanandree@gmail.com"]
10
+ # s.homepage = "http://example.com"
11
+ s.summary = %q{Middleman Extension that generates JSON and XML endpoints}
12
+ s.description = %q{Middleman Extension that generates JSON and XML endpoints}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # The version of middleman-core your extension depends on
20
+ s.add_runtime_dependency("middleman-core", [">= 3.0.12"])
21
+ s.add_runtime_dependency("middleman-more", [">= 3.0.12"])
22
+ s.add_runtime_dependency("activesupport", ["~> 3.2.12"])
23
+ end
data/readme.md ADDED
@@ -0,0 +1,69 @@
1
+ # Middleman API [![Build Status](https://travis-ci.org/jordanandree/middleman-api.png?branch=master)](https://travis-ci.org/jordanandree/middleman-api)
2
+
3
+ Create JSON and XML endpoints generated from template frontmatter and content.
4
+
5
+ ## Installation
6
+
7
+ Bundle with your Gemfile:
8
+
9
+ ```ruby
10
+ gem "middleman-api"
11
+ ```
12
+
13
+ Or install the standalone Gem:
14
+
15
+ ```ruby
16
+ gem install "middleman-api"
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Activate the extension in your `config.rb`:
22
+
23
+ ```ruby
24
+ activate :api
25
+ ```
26
+
27
+ The extension will then look over each template in the sitemap and proxy frontmatter and content to JSON and XML endpoints.
28
+
29
+ **JSON**
30
+
31
+ ```json
32
+ {
33
+ "meta" {
34
+ "title" : "Middleman",
35
+ "foo" : "bar"
36
+ },
37
+ "path" : "/index.html",
38
+ "content" : "..."
39
+ }
40
+ ```
41
+
42
+ **XML**
43
+
44
+ ```xml
45
+ <hash>
46
+ <meta>
47
+ <title>Middleman</title>
48
+ <foo>bar</foo>
49
+ </meta>
50
+ <path>/index.html</path>
51
+ <content>
52
+ ...
53
+ </content>
54
+ </hash>
55
+ ```
56
+
57
+ ## Contributing
58
+ If there is any thing you'd like to contribute or fix, please:
59
+
60
+ * Fork the repo
61
+ * Make your changes
62
+ * Add Cucumber tests for any new functionality
63
+ * Verify all existing tests work properly
64
+ * Make a pull request
65
+
66
+ The Cucumber features for this project assume the gem is installed, so to make any changes you will need to build and install the gem locally with your changes.
67
+
68
+ ## License
69
+ The middleman-api gem is Copyright 2013 Jordan Andree, distributed under the MIT License.
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-api
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - jordanandree
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2013-03-07 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: middleman-core
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.12
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: middleman-more
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.12
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: activesupport
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 3.2.12
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ description: Middleman Extension that generates JSON and XML endpoints
49
+ email:
50
+ - jordanandree@gmail.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - Gemfile
60
+ - LICENSE
61
+ - Rakefile
62
+ - features/json-api.feature
63
+ - features/support/env.rb
64
+ - features/tilt-formats.feature
65
+ - features/xml-api.feature
66
+ - fixtures/middleman-app/config.rb
67
+ - fixtures/middleman-app/source/images/background.png
68
+ - fixtures/middleman-app/source/images/middleman.png
69
+ - fixtures/middleman-app/source/index.html.erb
70
+ - fixtures/middleman-app/source/javascripts/all.js
71
+ - fixtures/middleman-app/source/layouts/layout.erb
72
+ - fixtures/middleman-app/source/no-frontmatter.html.erb
73
+ - fixtures/middleman-app/source/stylesheets/all.css
74
+ - fixtures/middleman-app/source/stylesheets/normalize.css
75
+ - fixtures/middleman-app/source/test.html.erb
76
+ - fixtures/middleman-app/source/tilt/haml.html.haml
77
+ - fixtures/middleman-app/source/tilt/liquid.html.liquid
78
+ - fixtures/middleman-app/source/tilt/markdown.html.md
79
+ - fixtures/middleman-app/source/tilt/rdoc.html.rdoc
80
+ - fixtures/middleman-app/source/tilt/slim.html.slim
81
+ - fixtures/middleman-app/source/tilt/textile.html.textile
82
+ - lib/middleman-api.rb
83
+ - lib/middleman-api/extension.rb
84
+ - lib/middleman-api/sitemap.rb
85
+ - lib/middleman-api/template.json.erb
86
+ - lib/middleman-api/template.rb
87
+ - lib/middleman-api/template.xml.erb
88
+ - lib/middleman_extension.rb
89
+ - middleman-api.gemspec
90
+ - readme.md
91
+ homepage:
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options: []
96
+
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: "0"
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: "0"
111
+ requirements: []
112
+
113
+ rubyforge_project:
114
+ rubygems_version: 1.8.24
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Middleman Extension that generates JSON and XML endpoints
118
+ test_files:
119
+ - features/json-api.feature
120
+ - features/support/env.rb
121
+ - features/tilt-formats.feature
122
+ - features/xml-api.feature
123
+ has_rdoc: