stasis-extensions 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/stasis/extensions/assets.rb +84 -0
- data/lib/stasis/extensions/i18n.rb +56 -0
- data/lib/stasis/extensions/version.rb +5 -0
- data/lib/stasis/extensions.rb +4 -0
- data/stasis-extensions.gemspec +23 -0
- metadata +94 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 S. Brent Faulkner
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Stasis::Extensions
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'stasis-extensions'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install stasis-extensions
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Stasis
|
2
|
+
module Extensions
|
3
|
+
class Assets < Stasis::Plugin
|
4
|
+
before_all :before_all
|
5
|
+
reset :reset
|
6
|
+
action_method :assets
|
7
|
+
|
8
|
+
def initialize(stasis)
|
9
|
+
@stasis = stasis
|
10
|
+
reset
|
11
|
+
end
|
12
|
+
|
13
|
+
def before_all
|
14
|
+
define_helpers
|
15
|
+
fingerprint_assets
|
16
|
+
Stasis::Options.set_template_option 'scss', { asset_resolver: self }
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset
|
20
|
+
@assets = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def resolve_path(path, dirpath)
|
24
|
+
path = File.expand_path(path, dirpath).sub("#{@stasis.root}/", '')
|
25
|
+
"/#{assets[path] || path}"
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def assets
|
31
|
+
@assets
|
32
|
+
end
|
33
|
+
|
34
|
+
def define_helpers
|
35
|
+
@stasis.controller.helpers do
|
36
|
+
def asset_path(path)
|
37
|
+
return path if path =~ %r"\A(?:https?:)?//[^/]+"
|
38
|
+
return asset_path(path[1..-1]) if path =~ %r"\A/"
|
39
|
+
"/#{assets[path] || path}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def asset_url(path)
|
43
|
+
"#{root_url}#{asset_path(path)}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def fingerprint_asset(source)
|
49
|
+
digest = Digest::MD5.file(source)
|
50
|
+
render_asset source, source.sub(/\.(?:erb|haml|scss)$/, ''), source.sub(/(\.(?:\w+))(\.(?:erb|haml|scss))?$/) { |m| "-#{digest}#{$1}" }
|
51
|
+
end
|
52
|
+
|
53
|
+
def fingerprint_assets
|
54
|
+
Dir['{css,images,js}/**/*'].each do |source|
|
55
|
+
next unless File.file?(source)
|
56
|
+
fingerprint_asset(source)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def render_asset(source, asset, output)
|
61
|
+
@assets[asset] = output
|
62
|
+
@stasis.controller.before output do
|
63
|
+
begin
|
64
|
+
@asset_path = asset
|
65
|
+
instead render(source, write: false)
|
66
|
+
ensure
|
67
|
+
@asset_path = nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
Stasis.register Stasis::Extensions::Assets
|
76
|
+
|
77
|
+
module Sass::Script::Functions
|
78
|
+
def asset_url(path)
|
79
|
+
assert_type path, :String
|
80
|
+
Sass::Script::String.new("url(#{options[:asset_resolver].resolve_path(path.value, File.dirname(options[:original_filename]))})")
|
81
|
+
end
|
82
|
+
|
83
|
+
declare :asset_url, :args => [:string]
|
84
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'i18n'
|
2
|
+
|
3
|
+
module Stasis
|
4
|
+
module Extensions
|
5
|
+
class I18n < Stasis::Plugin
|
6
|
+
before_all :before_all
|
7
|
+
reset :reset
|
8
|
+
|
9
|
+
def initialize(stasis)
|
10
|
+
@stasis = stasis
|
11
|
+
reset
|
12
|
+
end
|
13
|
+
|
14
|
+
def before_all
|
15
|
+
::I18n.locale = ENV['LOCALE'] || ::I18n.default_locale
|
16
|
+
define_helpers
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset
|
20
|
+
::I18n.load_path = Dir[File.expand_path('config/locales/*.yml', @stasis.root)]
|
21
|
+
::I18n.default_locale = :en
|
22
|
+
::I18n.reload!
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def define_helpers
|
28
|
+
@stasis.controller.helpers do
|
29
|
+
def body_class
|
30
|
+
[::I18n.locale, scope.last]
|
31
|
+
end
|
32
|
+
|
33
|
+
def relative_path
|
34
|
+
@asset_path || _stasis.path.sub("#{_stasis.root}/", '')
|
35
|
+
end
|
36
|
+
|
37
|
+
def root_url
|
38
|
+
"http://#{t('hostname', :scope => '')}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def scope
|
42
|
+
relative_path.sub(/\.\w+(\.(?:erb|haml|scss))?$/, '').split('/')
|
43
|
+
end
|
44
|
+
|
45
|
+
def t(*args)
|
46
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
47
|
+
options[:scope] ||= scope
|
48
|
+
::I18n.translate(*args, options)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Stasis.register Stasis::Extensions::I18n
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'stasis/extensions/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "stasis-extensions"
|
8
|
+
spec.version = Stasis::Extensions::VERSION
|
9
|
+
spec.authors = ["S. Brent Faulkner"]
|
10
|
+
spec.email = ["brent.faulkner@mosaic.com"]
|
11
|
+
spec.description = %q{plugin(s) for stasis providing i18n support and asset fingerprinting}
|
12
|
+
spec.summary = %q{plugin(s) for stasis providing i18n support and asset fingerprinting}
|
13
|
+
spec.homepage = "http://github.com/mosaicxm/stasis-extensions"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stasis-extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- S. Brent Faulkner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: plugin(s) for stasis providing i18n support and asset fingerprinting
|
47
|
+
email:
|
48
|
+
- brent.faulkner@mosaic.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/stasis/extensions.rb
|
59
|
+
- lib/stasis/extensions/assets.rb
|
60
|
+
- lib/stasis/extensions/i18n.rb
|
61
|
+
- lib/stasis/extensions/version.rb
|
62
|
+
- stasis-extensions.gemspec
|
63
|
+
homepage: http://github.com/mosaicxm/stasis-extensions
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
hash: 4589993883192778636
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
hash: 4589993883192778636
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.8.23
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: plugin(s) for stasis providing i18n support and asset fingerprinting
|
94
|
+
test_files: []
|