homeostasis 0.0.12 → 0.0.13

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.
Files changed (3) hide show
  1. data/README.md +29 -20
  2. data/lib/homeostasis.rb +22 -24
  3. metadata +2 -2
data/README.md CHANGED
@@ -7,7 +7,7 @@ trailing slashes.
7
7
  Installation
8
8
  ============
9
9
 
10
- % gem install homeostasis
10
+ $ gem install homeostasis
11
11
 
12
12
  In your controller:
13
13
 
@@ -36,15 +36,14 @@ You'll end up with something like this:
36
36
 
37
37
  Generated files in the `public` directory will go through a global search and
38
38
  replace. By default, it'll only do this on `html`, `css`, and `js` files.
39
- You can configure this:
39
+ You can configure this with the `replace_matcher` option. You can also
40
+ configure the regex for asset matching with `matcher`:
40
41
 
41
- Homeostasis::Asset.replace_matcher = /.(html|css|js)$/i
42
+ Homeostasis::Asset.config(
43
+ :replace_matcher => /.(html|css|js)$/i,
44
+ :matcher => /myregex$/i)
42
45
 
43
- You can set the regex for asset matching in your controller:
44
-
45
- Homeostasis::Asset.matcher = /myregex$/i
46
-
47
- You can also configure concatenation of multiple assets into a single file:
46
+ You can concatenate multiple assets into a single file:
48
47
 
49
48
  Homeostasis::Asset.concat 'all.js', %w(jquery.js mine.js)
50
49
  Homeostasis::Asset.concat 'all.css', %w(reset.css mine.css)
@@ -55,10 +54,10 @@ Blog
55
54
  In your controller:
56
55
 
57
56
  Homeostasis::Blog.config(
58
- 'blog', # directory of posts
59
- 'http://example.com', # site url
60
- 'Blog Title', # site title
61
- 'Blog Description for RSS feed') # site description
57
+ :directory => 'blog', # directory of posts, required
58
+ :url => 'http://example.com', # site url, required
59
+ :title => 'Blog Title',
60
+ :desc => 'Blog Description for RSS feed')
62
61
 
63
62
  Post files should be in the format `yyyy-mm-dd-permalink.html.md`. Use
64
63
  YAML front-matter for any metadata you want. `:date` and `:path` will be
@@ -98,12 +97,13 @@ ERB comments as well:
98
97
 
99
98
  You can configure which files to check in `controller.rb`. Here's the default:
100
99
 
101
- Homeostasis::Front.matchers = {
102
- 'erb' => /<%#/,
103
- 'haml' => /-#/,
104
- 'html' => /<!--/,
105
- 'md' => /<!--/
106
- }
100
+ Homeostasis::Front.config(
101
+ :matchers => {
102
+ 'erb' => /<%#/,
103
+ 'haml' => /-#/,
104
+ 'html' => /<!--/,
105
+ 'md' => /<!--/
106
+ })
107
107
 
108
108
  Just start the file with YAML inside a comment with 2-space indentation. The
109
109
  data will be available from the `front` method in your views and controller.
@@ -119,7 +119,10 @@ Sitemap
119
119
  A sitemap will automatically be generated in `public/sitemap.xml`. You'll need
120
120
  to set the root URL for this to happen:
121
121
 
122
- Homeostasis::Sitemap.url 'http://example.com'
122
+ Homeostasis::Sitemap.config(
123
+ :url => 'http://example.com', # required
124
+ :lastmod => false # default is true
125
+ )
123
126
 
124
127
  `loc` and `lastmod` will be generated for each page. Use front-yaml to set the
125
128
  `changefreq` or `priority`:
@@ -154,8 +157,14 @@ You'll get:
154
157
  This works well with an `htaccess` file that automatically appends trailing
155
158
  slashes to URLs.
156
159
 
160
+ TODO
161
+ ====
162
+
163
+ * make each plugin optional
164
+ * single version endpoint
165
+
157
166
  License
158
167
  =======
159
168
 
160
- Copyright 2012 Hugh Bien - http://hughbien.com.
169
+ Copyright Hugh Bien - http://hughbien.com.
161
170
  Released under BSD License, see LICENSE.md for more info.
data/lib/homeostasis.rb CHANGED
@@ -6,7 +6,7 @@ require 'yaml'
6
6
  require 'cgi'
7
7
 
8
8
  module Homeostasis
9
- VERSION = '0.0.12'
9
+ VERSION = '0.0.13'
10
10
 
11
11
  module Helpers
12
12
  private
@@ -68,7 +68,6 @@ module Homeostasis
68
68
  def after_all
69
69
  assets = {}
70
70
  strip_dest = (@stasis.destination.length + 1)..-1
71
- strip_root = (@stasis.root.length + 1)..-1
72
71
 
73
72
  # concatenate files with stamps
74
73
  @@orig_concats.each do |concatted, files|
@@ -99,7 +98,7 @@ module Homeostasis
99
98
  end
100
99
 
101
100
  # read contents of each file, search/replace assets with stamps
102
- Dir.glob("#{@stasis.destination[strip_root]}/**/*").each do |file|
101
+ Dir.glob("#{@stasis.destination}/**/*").each do |file|
103
102
  next if file !~ @@replace_matcher || File.directory?(file)
104
103
  contents = File.read(file)
105
104
  assets.each do |old, new|
@@ -128,12 +127,9 @@ module Homeostasis
128
127
  Digest::SHA1.hexdigest(versions.join('.'))
129
128
  end
130
129
 
131
- def self.matcher=(regex)
132
- @@matcher = regex
133
- end
134
-
135
- def self.replace_matcher=(regex)
136
- @@replace_matcher = regex
130
+ def self.config(options)
131
+ @@matcher = options[:matcher] if options[:matcher]
132
+ @@replace_matcher = options[:replace_matcher] if options[:replace_matcher]
137
133
  end
138
134
 
139
135
  def self.concat(dest, files)
@@ -204,8 +200,8 @@ module Homeostasis
204
200
  @@front_site
205
201
  end
206
202
 
207
- def self.matchers=(ext)
208
- @@matchers = ext
203
+ def self.config(options)
204
+ @@matchers = options[:matchers] if options[:matchers]
209
205
  end
210
206
 
211
207
  private
@@ -235,7 +231,7 @@ module Homeostasis
235
231
  end
236
232
 
237
233
  def after_all
238
- dest = @stasis.destination[(@stasis.root.length + 1)..-1]
234
+ dest = @stasis.destination
239
235
  Dir.glob("#{dest}/**/*.html").each do |filename|
240
236
  next if filename =~ /\/index\.html$/
241
237
  dir = "#{filename.sub(/\.html$/, '')}/"
@@ -254,8 +250,9 @@ module Homeostasis
254
250
  @@url = nil
255
251
  end
256
252
 
257
- def self.url(url)
258
- @@url = url
253
+ def self.config(options)
254
+ @@url = options[:url]
255
+ @@lastmod = options[:lastmod] || false
259
256
  end
260
257
 
261
258
  def after_all
@@ -279,7 +276,7 @@ module Homeostasis
279
276
  nil
280
277
  xml += " <url>\n"
281
278
  xml += " <loc>#{h(@@url + front[:path])}</loc>\n" if front[:path]
282
- xml += " <lastmod>#{h lastmod}</lastmod>\n" if lastmod
279
+ xml += " <lastmod>#{h lastmod}</lastmod>\n" if @@lastmod && lastmod
283
280
  xml += " <changefreq>#{h front[:changefreq]}</changefreq>\n" if front[:changefreq]
284
281
  xml += " <priority>#{h front[:priority]}</priority>\n" if front[:priority]
285
282
  xml += " </url>\n"
@@ -301,21 +298,22 @@ module Homeostasis
301
298
  def initialize(stasis)
302
299
  @stasis = stasis
303
300
  @@directory = nil
304
- @@link = nil
301
+ @@url = nil
305
302
  @@title = nil
306
303
  @@desc = nil
307
304
  @@posts = []
308
305
  end
309
306
 
310
- def self.config(directory, link, title, desc)
311
- @@directory = directory
312
- @@link = link
313
- @@title = title
314
- @@desc = desc
307
+ def self.config(options)
308
+ @@directory = options[:directory]
309
+ @@url = options[:url]
310
+ @@title = options[:title]
311
+ @@desc = options[:desc]
315
312
  end
316
313
 
317
314
  def before_all
318
315
  return if @@directory.nil?
316
+ @@posts = []
319
317
  front_site = Homeostasis::Front._front_site
320
318
  Dir.glob("#{File.join(@stasis.root, @@directory)}/*").each do |filename|
321
319
  next if File.basename(filename) !~ DATE_REGEX
@@ -337,17 +335,17 @@ module Homeostasis
337
335
  filename,
338
336
  File.join(File.dirname(filename), base.sub(DATE_REGEX, '')))
339
337
  end
340
- url = h("#{@@link}/#{@@directory}/")
338
+ url = h("#{@@url}/#{@@directory}/")
341
339
  rss = "<?xml version=\"1.0\"?>\n"
342
340
  rss += "<rss version=\"2.0\">\n"
343
341
  rss += " <channel>\n"
344
342
  rss += " <title>#{h @@title}</title>\n" if @@title
345
- rss += " <link>#{h @@link}/</link>\n" if @@link
343
+ rss += " <link>#{h @@url}/</link>\n" if @@url
346
344
  rss += " <description>#{h @@desc}</description>\n" if @@desc
347
345
  blog_posts[0..5].each do |post|
348
346
  rss += " <item>\n"
349
347
  rss += " <title>#{h post[:title]}</title>\n"
350
- rss += " <link>#{h(@@link + post[:path])}</link>\n"
348
+ rss += " <link>#{h(@@url + post[:path])}</link>\n"
351
349
  rss += " <pubDate>#{post[:date].strftime('%m-%d-%Y %H:%M')}</pubDate>\n"
352
350
  rss += " <description>#{h post[:body]}</description>\n"
353
351
  rss += " </item>\n"
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.12
4
+ version: 0.0.13
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-08-07 00:00:00.000000000 Z
12
+ date: 2012-10-14 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.