homeostasis 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +46 -4
- data/lib/homeostasis/front.rb +64 -0
- data/lib/homeostasis.rb +1 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Description
|
2
2
|
===========
|
3
3
|
|
4
|
-
Stasis plugin for asset stamping with git revisions,
|
5
|
-
and uri helpers.
|
4
|
+
Stasis plugin for asset stamping with git revisions, yaml front-matter,
|
5
|
+
environment branching, and uri helpers.
|
6
6
|
|
7
7
|
Installation
|
8
8
|
============
|
@@ -13,13 +13,14 @@ In your controller:
|
|
13
13
|
|
14
14
|
require 'rubygems'
|
15
15
|
require 'homeostasis/asset' # for asset stamping
|
16
|
+
require 'homeostasis/front' # for yaml front-matter
|
16
17
|
require 'homeostasis/env' # for environment handler
|
17
18
|
require 'homeostasis/path' # for path helpers
|
18
19
|
|
19
20
|
Each component is optional.
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
Asset Stamping
|
23
|
+
==============
|
23
24
|
|
24
25
|
By default, assets matching `/\.(jpg|png|gif|css|js)$/i` will be stamped.
|
25
26
|
So if your root directory is like this:
|
@@ -58,6 +59,9 @@ You can even concat your assets into a single file:
|
|
58
59
|
%link{:href => asset_path('all.css')}
|
59
60
|
%script{:src => asset_path('all.js')}
|
60
61
|
|
62
|
+
Environment Handler
|
63
|
+
===================
|
64
|
+
|
61
65
|
The environment handler just adds a variable:
|
62
66
|
|
63
67
|
Homeostasis::ENV
|
@@ -67,6 +71,44 @@ can use this to branch in your view:
|
|
67
71
|
|
68
72
|
= Homeostasis::ENV.development? ? 'local.js' : 'production.js'
|
69
73
|
|
74
|
+
YAML Front-matter
|
75
|
+
=================
|
76
|
+
|
77
|
+
This adds YAML front-matter support:
|
78
|
+
|
79
|
+
#!
|
80
|
+
:title: Lorem Ipsum
|
81
|
+
:desc: Quick fox over lazy dog.
|
82
|
+
%div
|
83
|
+
Page continues as normal here
|
84
|
+
%h1= front[:title]
|
85
|
+
%p= front[:desc]
|
86
|
+
|
87
|
+
Note the 2-space indentation is required. This works for HTML, Markdown, and
|
88
|
+
ERB comments as well:
|
89
|
+
|
90
|
+
<!--
|
91
|
+
:title: Lorem Ipsum
|
92
|
+
-->
|
93
|
+
Continue as normal
|
94
|
+
|
95
|
+
You can configure which files to check in `controller.rb`. Here's the default:
|
96
|
+
|
97
|
+
Homeostasis::Front.matchers = {
|
98
|
+
'erb' => /<%#/,
|
99
|
+
'haml' => /-#/,
|
100
|
+
'html' => /<!--/,
|
101
|
+
'md' => /<!--/
|
102
|
+
}
|
103
|
+
|
104
|
+
Just start the file with YAML inside a comment with 2-space indentation. The
|
105
|
+
data will be available from the `front` method in your views and controller.
|
106
|
+
There's also a `front_site` helper which contains the data for all pages for
|
107
|
+
cross-page access.
|
108
|
+
|
109
|
+
Path Helper
|
110
|
+
===========
|
111
|
+
|
70
112
|
The path helper uses the environment handler. It just adds the view helper
|
71
113
|
`path` which returns differently depending on the environment:
|
72
114
|
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'homeostasis')
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class Homeostasis::Front < Stasis::Plugin
|
5
|
+
before_all :before_all
|
6
|
+
action_method :front
|
7
|
+
action_method :front_site
|
8
|
+
|
9
|
+
def initialize(stasis)
|
10
|
+
@stasis = stasis
|
11
|
+
@front_site = {}
|
12
|
+
@@matchers = {
|
13
|
+
'erb' => /<%#/,
|
14
|
+
'haml' => /-#/,
|
15
|
+
'html' => /<!--/,
|
16
|
+
'md' => /<!--/
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def before_all
|
21
|
+
@stasis.paths.each do |path|
|
22
|
+
next if path !~ /\.(#{@@matchers.keys.join('|')})$/
|
23
|
+
contents = File.read(path)
|
24
|
+
next if contents !~ @@matchers[File.extname(path)[1..-1]]
|
25
|
+
|
26
|
+
lines, data, index = contents.split("\n"), "", 1
|
27
|
+
while index < lines.size
|
28
|
+
break if lines[index] !~ /^ /
|
29
|
+
data += lines[index] + "\n"
|
30
|
+
index += 1
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
yaml = YAML.load(data)
|
35
|
+
@front_site[front_key(path)] = yaml if yaml.is_a?(Hash)
|
36
|
+
rescue Psych::SyntaxError => error
|
37
|
+
next
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def front
|
43
|
+
@front_site[front_key(@stasis.path)] || {}
|
44
|
+
end
|
45
|
+
|
46
|
+
def front_site
|
47
|
+
@front_site
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.matchers
|
51
|
+
@@matchers
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.matchers=(ext)
|
55
|
+
@@matchers = ext
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
def front_key(filename)
|
60
|
+
filename.sub(Dir.pwd, '')[1..-1].sub(/\.[^.]+$/, '')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Stasis.register(Homeostasis::Front)
|
data/lib/homeostasis.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: homeostasis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.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: 2012-
|
12
|
+
date: 2012-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Provides asset stamping using git revisions, environments, and a few
|
15
15
|
view helpers.
|
@@ -22,6 +22,7 @@ files:
|
|
22
22
|
- LICENSE.md
|
23
23
|
- README.md
|
24
24
|
- lib/homeostasis/env.rb
|
25
|
+
- lib/homeostasis/front.rb
|
25
26
|
- lib/homeostasis/path.rb
|
26
27
|
- lib/homeostasis/asset.rb
|
27
28
|
- lib/homeostasis.rb
|