css_views 0.5.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/css_views/configuration.rb +21 -0
- data/lib/css_views/controller_mixins.rb +34 -0
- data/lib/css_views/handler.rb +47 -0
- data/lib/css_views.rb +7 -0
- metadata +89 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
module CssViews
|
2
|
+
class Configuration
|
3
|
+
def initialize(name, options)
|
4
|
+
@name = name
|
5
|
+
@options = options
|
6
|
+
end
|
7
|
+
|
8
|
+
def components
|
9
|
+
@options[:components]
|
10
|
+
end
|
11
|
+
|
12
|
+
def transformers
|
13
|
+
@options[:transformers]
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def handler(controller)
|
18
|
+
Handler.new(self, controller)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module CssViews
|
2
|
+
module ControllerMixins
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
included do
|
5
|
+
cattr_accessor :configurations
|
6
|
+
self.configurations = {}
|
7
|
+
caches_page :show
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def css_configuration(name, options)
|
12
|
+
self.configurations[name.to_s] = Configuration.new(name, options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module InstanceMethods
|
17
|
+
def show
|
18
|
+
configuration = self.class.configurations[params[:configuration_name]]
|
19
|
+
head :not_found unless configuration
|
20
|
+
|
21
|
+
handler = configuration.handler(self)
|
22
|
+
if perform_caching
|
23
|
+
fresh_when(:etag=>handler.etag, :last_modified=>handler.last_modified, :public=>true)
|
24
|
+
if params[:cache_buster]
|
25
|
+
response.headers['Cache-Control']= 'public, max-age=131557600'
|
26
|
+
response.headers['Expires'] = 10.years.from_now.httpdate
|
27
|
+
end
|
28
|
+
return if performed?
|
29
|
+
end
|
30
|
+
render :text=>handler.render, :type=>Mime::CSS
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module CssViews
|
2
|
+
class Handler
|
3
|
+
def initialize(configuration, controller)
|
4
|
+
@configuration = configuration
|
5
|
+
@controller = controller
|
6
|
+
end
|
7
|
+
|
8
|
+
def render
|
9
|
+
transform(body)
|
10
|
+
end
|
11
|
+
|
12
|
+
def body
|
13
|
+
@configuration.components.map do |view|
|
14
|
+
@controller.send(:render_to_string, view)
|
15
|
+
end.join("\n")
|
16
|
+
end
|
17
|
+
|
18
|
+
def last_modified
|
19
|
+
template_files.map {|f| File.mtime(f) }.max
|
20
|
+
end
|
21
|
+
|
22
|
+
def etag
|
23
|
+
template_files.map {|f| File.mtime(f) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def transform(css)
|
27
|
+
if transformers = @configuration.transformers
|
28
|
+
transformers.each do |transformer|
|
29
|
+
css = transformer.transform(css)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
css
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def lookup_context
|
37
|
+
@controller.send(:lookup_context)
|
38
|
+
end
|
39
|
+
|
40
|
+
def template_files
|
41
|
+
@template_files ||= @configuration.components.map do |name|
|
42
|
+
lookup_context.find(name, "stylesheets", false).identifier
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/lib/css_views.rb
ADDED
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: css_views
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 961916012
|
5
|
+
prerelease: true
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
- pre
|
11
|
+
version: 0.5.0.pre
|
12
|
+
platform: ruby
|
13
|
+
authors:
|
14
|
+
- Michael Koziarski
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-09-06 00:00:00 +12:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: actionpack
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 7712042
|
31
|
+
segments:
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
- 0
|
35
|
+
- rc
|
36
|
+
version: 3.0.0.rc
|
37
|
+
type: :runtime
|
38
|
+
version_requirements: *id001
|
39
|
+
description: Gives you helpers and the like when composing stylesheets
|
40
|
+
email: michael@koziarski.com
|
41
|
+
executables: []
|
42
|
+
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files: []
|
46
|
+
|
47
|
+
files:
|
48
|
+
- lib/css_views/configuration.rb
|
49
|
+
- lib/css_views/controller_mixins.rb
|
50
|
+
- lib/css_views/handler.rb
|
51
|
+
- lib/css_views.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://www.radionz.co.nz/
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 25
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 3
|
79
|
+
- 1
|
80
|
+
version: 1.3.1
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.3.7
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Simple Controller support
|
88
|
+
test_files: []
|
89
|
+
|