genki-merb_dynamic_sass 0.0.3

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.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Your Name
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,83 @@
1
+ MerbDynamicSass
2
+ ===============
3
+
4
+ A slice for the Merb framework.
5
+
6
+ How to use:
7
+ Put your sass temlates under the Merb.root / app / views / stylesheets directory,
8
+ then you could get the stylesheet compiled by Sass::Engine,
9
+ your temlate could also include ERB syntax, and you could use helper methods as well.
10
+
11
+ The correspondence between template and route is below:
12
+
13
+ GET "/stylesheets/some.css" --> using Merb.root /app/views/stylesheets/some.css.erb
14
+ GET "/stylesheets/somedir/some.css" --> using Merb.root /app/views/stylesheets/somedir/some.css.erb
15
+
16
+ How to get static file under the Merb.root/public/stylesheets directory:
17
+
18
+ Generated file is usually cached under the Merb.root/tmp/cache/stylesheets.
19
+ If you want the cache file to be cached under the Merb.root/public/stylesheet direcotry,
20
+ you should set the following configuration.
21
+
22
+ Merb::Slices.config[:merb_dynamic_sass][:page_cache] => true
23
+
24
+ (Note that this slice is not registed in production environment.)
25
+
26
+
27
+ -----------------------------------------------------------------------------
28
+
29
+ Instructions for installation:
30
+
31
+ file: config/router.rb
32
+
33
+ Usually you have to add routes of the slice, but this slice automatically add routes
34
+ because it seems that the route used for this porpose is fixed.
35
+
36
+
37
+ Also you probably don't have to run the following rake task:
38
+
39
+ rake slices:merb_dynamic_sass:install
40
+
41
+
42
+ file: config/init.rb
43
+
44
+ # add the slice as a regular dependency
45
+
46
+ dependency 'merb_dynamic_sass'
47
+
48
+ # if needed, configure which slices to load and in which order
49
+
50
+ Merb::Plugins.config[:merb_slices] = { :queue => ["MerbDynamicSass", ...] }
51
+
52
+ # optionally configure the plugins in a before_app_loads callback
53
+
54
+ Merb::BootLoader.before_app_loads do
55
+
56
+ Merb::Slices::config[:merb_dynamic_sass][:option] = value
57
+
58
+ end
59
+
60
+ ------------------------------------------------------------------------------
61
+
62
+ You can put your application-level overrides in:
63
+
64
+ host-app/slices/merb_dynamic_sass/app - controllers, models, views ...
65
+
66
+ Templates are located in this order:
67
+
68
+ 1. host-app/slices/merb_dynamic_sass/app/views/*
69
+ 2. gems/merb_dynamic_sass/app/views/*
70
+ 3. host-app/app/views/*
71
+
72
+ You can use the host application's layout by configuring the
73
+ merb_dynamic_sass slice in a before_app_loads block:
74
+
75
+ Merb::Slices.config[:merb_dynamic_sass] = { :layout => :application }
76
+
77
+ By default :merb_dynamic_sass is used. If you need to override
78
+ stylesheets or javascripts, just specify your own files in your layout
79
+ instead/in addition to the ones supplied (if any) in
80
+ host-app/public/slices/merb_dynamic_sass.
81
+
82
+ In any case don't edit those files directly as they may be clobbered any time
83
+ rake merb_dynamic_sass:install is run.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ require 'merb-core'
5
+ require 'merb-core/tasks/merb'
6
+
7
+ GEM_NAME = "merb_dynamic_sass"
8
+ AUTHOR = "Yukiko Kawamoto"
9
+ EMAIL = "yu0420@gmail.com"
10
+ HOMEPAGE = "http://github.com/yukiko"
11
+ SUMMARY = "Merb Dynamic Sass is a Merb Slice that provides more handy way to use Sass engine."
12
+ GEM_VERSION = "0.0.3"
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.rubyforge_project = 'merb'
16
+ s.name = GEM_NAME
17
+ s.version = GEM_VERSION
18
+ s.platform = Gem::Platform::RUBY
19
+ s.has_rdoc = true
20
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
21
+ s.summary = SUMMARY
22
+ s.description = s.summary
23
+ s.author = AUTHOR
24
+ s.email = EMAIL
25
+ s.homepage = HOMEPAGE
26
+ s.add_dependency('merb-slices', '>= 1.0.9')
27
+ s.add_dependency('merb-cache', '>= 1.0.9')
28
+ s.require_path = 'lib'
29
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec,app,public,stubs}/**/*")
30
+ end
31
+
32
+ Rake::GemPackageTask.new(spec) do |pkg|
33
+ pkg.gem_spec = spec
34
+ end
35
+
36
+ desc "Install the gem"
37
+ task :install do
38
+ Merb::RakeHelper.install(GEM_NAME, :version => GEM_VERSION)
39
+ end
40
+
41
+ desc "Uninstall the gem"
42
+ task :uninstall do
43
+ Merb::RakeHelper.uninstall(GEM_NAME, :version => GEM_VERSION)
44
+ end
45
+
46
+ desc "Create a gemspec file"
47
+ task :gemspec do
48
+ File.open("#{GEM_NAME}.gemspec", "w") do |file|
49
+ file.puts spec.to_ruby
50
+ end
51
+ end
52
+
53
+ require 'spec/rake/spectask'
54
+ require 'merb-core/test/tasks/spectasks'
55
+ desc 'Default: run spec examples'
56
+ task :default => 'spec'
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ TODO:
2
+ - Enable to pass some configurations to Sass::Engine.
@@ -0,0 +1,5 @@
1
+ class MerbDynamicSass::Application < Merb::Controller
2
+
3
+ controller_for_slice
4
+
5
+ end
@@ -0,0 +1,65 @@
1
+ class MerbDynamicSass::Stylesheets < MerbDynamicSass::Application
2
+ provides :css
3
+ layout false
4
+
5
+ self._template_roots << [Merb.dir_for(:view), :_dynamic_sass_template_location]
6
+ def _dynamic_sass_template_location(context, type, controller)
7
+ _template_location(@template_path, type, "stylesheets")
8
+ end
9
+ private :_dynamic_sass_template_location
10
+
11
+ def _slice_template_location(context, type = nil, controller = controller_name)
12
+ super(@template_path, type, controller)
13
+ end
14
+ private :_slice_template_location
15
+
16
+ def self.page_cache?
17
+ Merb::Slices.config[:merb_dynamic_sass][:page_cache]
18
+ end
19
+
20
+ if page_cache?
21
+ cache :index, :store => MerbDynamicSass.page_cache_store_name
22
+ end
23
+
24
+
25
+ def index(path)
26
+ @template_path = path
27
+ if self.slice.action_cache_store.exists?(_cache_path)
28
+
29
+ m_template = File.mtime _location_of_template
30
+ m_cache = File.mtime _location_of_cache
31
+
32
+ if m_template > m_cache
33
+ self.slice.action_cache_store.delete _cache_path
34
+ end
35
+
36
+ end
37
+
38
+ self.content_type = :css
39
+ self.slice.action_cache_store.fetch _cache_path do
40
+ sass = render(:format => :css)
41
+ Sass::Engine.new(sass).to_css
42
+ end
43
+ end
44
+
45
+ def _cache_path
46
+ "#{@template_path}.css"
47
+ end
48
+ private :_cache_path
49
+
50
+ def _location_of_template
51
+ file = nil
52
+ self.class._template_roots.reverse_each do |root, template_method|
53
+ f = root / self.send(template_method, @template_path, :css, nil)
54
+ file = "#{f}.erb" and break if File.exists?("#{f}.erb")
55
+ end
56
+ file
57
+ end
58
+ private :_location_of_template
59
+
60
+ def _location_of_cache
61
+ self.slice.action_cache_store.pathify _cache_path
62
+ end
63
+ private :_location_of_cache
64
+
65
+ end
@@ -0,0 +1,64 @@
1
+ module Merb
2
+ module MerbDynamicSass
3
+ module ApplicationHelper
4
+
5
+ # @param *segments<Array[#to_s]> Path segments to append.
6
+ #
7
+ # @return <String>
8
+ # A path relative to the public directory, with added segments.
9
+ def image_path(*segments)
10
+ public_path_for(:image, *segments)
11
+ end
12
+
13
+ # @param *segments<Array[#to_s]> Path segments to append.
14
+ #
15
+ # @return <String>
16
+ # A path relative to the public directory, with added segments.
17
+ def javascript_path(*segments)
18
+ public_path_for(:javascript, *segments)
19
+ end
20
+
21
+ # @param *segments<Array[#to_s]> Path segments to append.
22
+ #
23
+ # @return <String>
24
+ # A path relative to the public directory, with added segments.
25
+ def stylesheet_path(*segments)
26
+ public_path_for(:stylesheet, *segments)
27
+ end
28
+
29
+ # Construct a path relative to the public directory
30
+ #
31
+ # @param <Symbol> The type of component.
32
+ # @param *segments<Array[#to_s]> Path segments to append.
33
+ #
34
+ # @return <String>
35
+ # A path relative to the public directory, with added segments.
36
+ def public_path_for(type, *segments)
37
+ ::MerbDynamicSass.public_path_for(type, *segments)
38
+ end
39
+
40
+ # Construct an app-level path.
41
+ #
42
+ # @param <Symbol> The type of component.
43
+ # @param *segments<Array[#to_s]> Path segments to append.
44
+ #
45
+ # @return <String>
46
+ # A path within the host application, with added segments.
47
+ def app_path_for(type, *segments)
48
+ ::MerbDynamicSass.app_path_for(type, *segments)
49
+ end
50
+
51
+ # Construct a slice-level path.
52
+ #
53
+ # @param <Symbol> The type of component.
54
+ # @param *segments<Array[#to_s]> Path segments to append.
55
+ #
56
+ # @return <String>
57
+ # A path within the slice source (Gem), with added segments.
58
+ def slice_path_for(type, *segments)
59
+ ::MerbDynamicSass.slice_path_for(type, *segments)
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5
+ <title>Fresh MerbDynamicSass Slice</title>
6
+ <link href="<%= public_path_for :stylesheet, 'master.css' %>" type="text/css" charset="utf-8" rel="stylesheet" media="all" />
7
+ <script src="<%= public_path_for :javascript, 'master.js' %>" type="text/javascript" charset="utf-8"></script>
8
+ </head>
9
+ <!-- you can override this layout at slices/merb_dynamic_sass/app/views/layout/merb_dynamic_sass.html.erb -->
10
+ <body class="merb_dynamic_sass-slice">
11
+ <div id="container">
12
+ <h1>MerbDynamicSass Slice</h1>
13
+ <div id="main"><%= catch_content :for_layout %></div>
14
+ </div>
15
+ </body>
16
+ </html>
@@ -0,0 +1,103 @@
1
+ namespace :slices do
2
+ namespace :merb_dynamic_sass do
3
+
4
+ desc "Install MerbDynamicSass"
5
+ task :install => [:preflight, :setup_directories, :copy_assets, :migrate]
6
+
7
+ desc "Test for any dependencies"
8
+ task :preflight do # see slicetasks.rb
9
+ end
10
+
11
+ desc "Setup directories"
12
+ task :setup_directories do
13
+ puts "Creating directories for host application"
14
+ MerbDynamicSass.mirrored_components.each do |type|
15
+ if File.directory?(MerbDynamicSass.dir_for(type))
16
+ if !File.directory?(dst_path = MerbDynamicSass.app_dir_for(type))
17
+ relative_path = dst_path.relative_path_from(Merb.root)
18
+ puts "- creating directory :#{type} #{File.basename(Merb.root) / relative_path}"
19
+ mkdir_p(dst_path)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ # desc "Copy stub files to host application"
26
+ # task :stubs do
27
+ # puts "Copying stubs for MerbDynamicSass - resolves any collisions"
28
+ # copied, preserved = MerbDynamicSass.mirror_stubs!
29
+ # puts "- no files to copy" if copied.empty? && preserved.empty?
30
+ # copied.each { |f| puts "- copied #{f}" }
31
+ # preserved.each { |f| puts "! preserved override as #{f}" }
32
+ # end
33
+
34
+ # desc "Copy stub files and views to host application"
35
+ # task :patch => [ "stubs", "freeze:views" ]
36
+
37
+ desc "Copy public assets to host application"
38
+ task :copy_assets do
39
+ puts "Copying assets for MerbDynamicSass - resolves any collisions"
40
+ copied, preserved = MerbDynamicSass.mirror_public!
41
+ puts "- no files to copy" if copied.empty? && preserved.empty?
42
+ copied.each { |f| puts "- copied #{f}" }
43
+ preserved.each { |f| puts "! preserved override as #{f}" }
44
+ end
45
+
46
+ desc "Migrate the database"
47
+ task :migrate do # see slicetasks.rb
48
+ end
49
+
50
+ desc "Freeze MerbDynamicSass into your app (only merb_dynamic_sass/app)"
51
+ task :freeze => [ "freeze:app" ]
52
+
53
+ namespace :freeze do
54
+
55
+ # desc "Freezes MerbDynamicSass by installing the gem into application/gems"
56
+ # task :gem do
57
+ # ENV["GEM"] ||= "merb_dynamic_sass"
58
+ # Rake::Task['slices:install_as_gem'].invoke
59
+ # end
60
+
61
+ desc "Freezes MerbDynamicSass by copying all files from merb_dynamic_sass/app to your application"
62
+ task :app do
63
+ puts "Copying all merb_dynamic_sass/app files to your application - resolves any collisions"
64
+ copied, preserved = MerbDynamicSass.mirror_app!
65
+ puts "- no files to copy" if copied.empty? && preserved.empty?
66
+ copied.each { |f| puts "- copied #{f}" }
67
+ preserved.each { |f| puts "! preserved override as #{f}" }
68
+ end
69
+
70
+ desc "Freeze all views into your application for easy modification"
71
+ task :views do
72
+ puts "Copying all view templates to your application - resolves any collisions"
73
+ copied, preserved = MerbDynamicSass.mirror_files_for :view
74
+ puts "- no files to copy" if copied.empty? && preserved.empty?
75
+ copied.each { |f| puts "- copied #{f}" }
76
+ preserved.each { |f| puts "! preserved override as #{f}" }
77
+ end
78
+
79
+ desc "Freeze all models into your application for easy modification"
80
+ task :models do
81
+ puts "Copying all models to your application - resolves any collisions"
82
+ copied, preserved = MerbDynamicSass.mirror_files_for :model
83
+ puts "- no files to copy" if copied.empty? && preserved.empty?
84
+ copied.each { |f| puts "- copied #{f}" }
85
+ preserved.each { |f| puts "! preserved override as #{f}" }
86
+ end
87
+
88
+ desc "Freezes MerbDynamicSass as a gem and copies over merb_dynamic_sass/app"
89
+ task :app_with_gem => [:gem, :app]
90
+
91
+ desc "Freezes MerbDynamicSass by unpacking all files into your application"
92
+ task :unpack do
93
+ puts "Unpacking MerbDynamicSass files to your application - resolves any collisions"
94
+ copied, preserved = MerbDynamicSass.unpack_slice!
95
+ puts "- no files to copy" if copied.empty? && preserved.empty?
96
+ copied.each { |f| puts "- copied #{f}" }
97
+ preserved.each { |f| puts "! preserved override as #{f}" }
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,20 @@
1
+ namespace :slices do
2
+ namespace :merb_dynamic_sass do
3
+
4
+ # add your own merb_dynamic_sass tasks here
5
+
6
+ # # Uncomment the following lines and edit the pre defined tasks
7
+ #
8
+ # # implement this to test for structural/code dependencies
9
+ # # like certain directories or availability of other files
10
+ # desc "Test for any dependencies"
11
+ # task :preflight do
12
+ # end
13
+ #
14
+ # # implement this to perform any database related setup steps
15
+ # desc "Migrate the database"
16
+ # task :migrate do
17
+ # end
18
+
19
+ end
20
+ end
@@ -0,0 +1,53 @@
1
+ namespace :slices do
2
+ namespace :merb_dynamic_sass do
3
+
4
+ desc "Run slice specs within the host application context"
5
+ task :spec => [ "spec:explain", "spec:default" ]
6
+
7
+ namespace :spec do
8
+
9
+ slice_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
10
+
11
+ task :explain do
12
+ puts "\nNote: By running MerbDynamicSass specs inside the application context any\n" +
13
+ "overrides could break existing specs. This isn't always a problem,\n" +
14
+ "especially in the case of views. Use these spec tasks to check how\n" +
15
+ "well your application conforms to the original slice implementation."
16
+ end
17
+
18
+ Spec::Rake::SpecTask.new('default') do |t|
19
+ t.spec_opts = ["--format", "specdoc", "--colour"]
20
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
21
+ end
22
+
23
+ desc "Run all model specs, run a spec for a specific Model with MODEL=MyModel"
24
+ Spec::Rake::SpecTask.new('model') do |t|
25
+ t.spec_opts = ["--format", "specdoc", "--colour"]
26
+ if(ENV['MODEL'])
27
+ t.spec_files = Dir["#{slice_root}/spec/models/**/#{ENV['MODEL']}_spec.rb"].sort
28
+ else
29
+ t.spec_files = Dir["#{slice_root}/spec/models/**/*_spec.rb"].sort
30
+ end
31
+ end
32
+
33
+ desc "Run all request specs, run a spec for a specific request with REQUEST=MyRequest"
34
+ Spec::Rake::SpecTask.new('request') do |t|
35
+ t.spec_opts = ["--format", "specdoc", "--colour"]
36
+ if(ENV['REQUEST'])
37
+ t.spec_files = Dir["#{slice_root}/spec/requests/**/#{ENV['REQUEST']}_spec.rb"].sort
38
+ else
39
+ t.spec_files = Dir["#{slice_root}/spec/requests/**/*_spec.rb"].sort
40
+ end
41
+ end
42
+
43
+ desc "Run all specs and output the result in html"
44
+ Spec::Rake::SpecTask.new('html') do |t|
45
+ t.spec_opts = ["--format", "html"]
46
+ t.libs = ['lib', 'server/lib' ]
47
+ t.spec_files = Dir["#{slice_root}/spec/**/*_spec.rb"].sort
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,119 @@
1
+ if defined?(Merb::Plugins)
2
+
3
+ $:.unshift File.dirname(__FILE__)
4
+
5
+ dependency 'merb-slices', :immediate => true
6
+ Merb::Plugins.add_rakefiles "merb_dynamic_sass/merbtasks", "merb_dynamic_sass/slicetasks", "merb_dynamic_sass/spectasks"
7
+
8
+ # Register the Slice for the current host application
9
+ # * This slice is not intended to be used in production environment
10
+ Merb::Slices::register(__FILE__) unless Merb.environment == "production"
11
+
12
+ # Slice configuration - set this in a before_app_loads callback.
13
+ # By default a Slice uses its own layout, so you can swicht to
14
+ # the main application layout or no layout at all if needed.
15
+ #
16
+ # Configuration options:
17
+ # :layout - the layout to use; defaults to :merb_dynamic_sass
18
+ # :mirror - which path component types to use on copy operations; defaults to all
19
+ Merb::Slices::config[:merb_dynamic_sass][:layout] ||= :merb_dynamic_sass
20
+
21
+ # All Slice code is expected to be namespaced inside a module
22
+ module MerbDynamicSass
23
+
24
+ # Slice metadata
25
+ def self.description
26
+ "MerbDynamicSass is a slice to provide more handy way to use Sass engine."
27
+ end
28
+
29
+ def self.version
30
+ "0.0.1"
31
+ end
32
+
33
+ def self.author
34
+ "Yukiko Kawamoto"
35
+ end
36
+
37
+ # Stub classes loaded hook - runs before LoadClasses BootLoader
38
+ # right after a slice's classes have been loaded internally.
39
+ def self.loaded
40
+ end
41
+
42
+ # Initialization hook - runs before AfterAppLoads BootLoader
43
+ # * use @initialized because sometimes self.init is called twice,
44
+ # especially during the spec or rake process.
45
+ attr_reader :initialized
46
+ def self.init
47
+ unless @initialized
48
+ require "sass"
49
+ # route is automatically prepared.
50
+ Merb::Router.prepare [], Merb::Router.routes do
51
+ slice(:merb_dynamic_sass, :name_prefix => nil)
52
+ end
53
+ Merb.add_mime_type(:css, :to_css, %w[text/css])
54
+ Merb.cache.register(action_cache_store_name, Merb::Cache::FileStore, :dir => Merb.root_path( :tmp / :cache / :stylesheets ))
55
+ Merb.cache.register(page_cache_store_name, Merb::Cache::PageStore[Merb::Cache::FileStore], :dir => Merb.root_path( "public" ))
56
+ @initialized = true
57
+ end
58
+ end
59
+
60
+ # Activation hook - runs after AfterAppLoads BootLoader
61
+ def self.activate
62
+ end
63
+
64
+ # Deactivation hook - triggered by Merb::Slices.deactivate(MerbDynamicSass)
65
+ def self.deactivate
66
+ end
67
+
68
+ # Setup routes inside the host application
69
+ #
70
+ # @param scope<Merb::Router::Behaviour>
71
+ # Routes will be added within this scope (namespace). In fact, any
72
+ # router behaviour is a valid namespace, so you can attach
73
+ # routes at any level of your router setup.
74
+ #
75
+ # @note prefix your named routes with :merb_dynamic_sass_
76
+ # to avoid potential conflicts with global named routes.
77
+ def self.setup_router(scope)
78
+ # example of a named route
79
+ scope.match(%r{^/stylesheets/(.*)\.css$}).to(:controller => "stylesheets", :action => "index", :path => "[1]").name :css
80
+ end
81
+
82
+ def self.action_cache_store_name
83
+ :dynamic_sass_action_cache
84
+ end
85
+
86
+ def self.page_cache_store_name
87
+ :dynamic_sass_page_cache
88
+ end
89
+
90
+ def self.action_cache_store
91
+ Merb::Cache[action_cache_store_name]
92
+ end
93
+
94
+ def self.page_cache_store
95
+ Merb::Cache[page_cache_store_name]
96
+ end
97
+
98
+ end
99
+
100
+ # Setup the slice layout for MerbDynamicSass
101
+ #
102
+ # Use MerbDynamicSass.push_path and MerbDynamicSass.push_app_path
103
+ # to set paths to merb_dynamic_sass-level and app-level paths. Example:
104
+ #
105
+ # MerbDynamicSass.push_path(:application, MerbDynamicSass.root)
106
+ # MerbDynamicSass.push_app_path(:application, Merb.root / 'slices' / 'merb_dynamic_sass')
107
+ # ...
108
+ #
109
+ # Any component path that hasn't been set will default to MerbDynamicSass.root
110
+ #
111
+ # Or just call setup_default_structure! to setup a basic Merb MVC structure.
112
+ MerbDynamicSass.setup_default_structure!
113
+
114
+ # Add dependencies for other MerbDynamicSass classes below. Example:
115
+ # dependency "merb_dynamic_sass/other"
116
+ dependency "merb-cache"
117
+ dependency "merb-action-args"
118
+
119
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ html, body { margin: 0; padding: 0; }
2
+ #container { width: 800px; margin: 4em auto; padding: 4em 4em 6em 4em; background: #DDDDDD; }
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "MerbDynamicSass (module)" do
4
+
5
+ describe "with Merb::Cache" do
6
+
7
+ it "has self.action_cache_store and self.page_cache_store" do
8
+ MerbDynamicSass.action_cache_store.should be_a(Merb::Cache::FileStore)
9
+ MerbDynamicSass.page_cache_store.should be_a(Merb::Cache::PageStore)
10
+ end
11
+
12
+ it "has the store for action cache whose dir is Merb.root/:tmp/:cache/:stylesheets" do
13
+ store = MerbDynamicSass.action_cache_store
14
+ store.dir.should == (Merb.root_path(:tmp/:cache/:stylesheets))
15
+ store.pathify("basic.css").should == (Merb.root_path(:tmp/:cache/:stylesheets/ "basic.css"))
16
+ store.pathify("somedir/basic.css").should == (Merb.root_path(:tmp/:cache/:stylesheets/:somedir/"basic.css"))
17
+ end
18
+
19
+ it "has the store for page cache whose dir is Merb.root/:public" do
20
+ store = MerbDynamicSass.page_cache_store.stores.first
21
+ store.dir.should == (Merb.root/:public)
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
@@ -0,0 +1,117 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
2
+ require "pp"
3
+
4
+ describe "GET /stylesheets/filepath.css" do
5
+
6
+ before(:all) do
7
+ mount_slice
8
+ @store = MerbDynamicSass.action_cache_store
9
+ @file = MerbDynamicSass.dir_for(:view) / :stylesheets / "basic.css.erb"
10
+
11
+ # This direcotry is necessary for this test.
12
+ template_dir = MerbDynamicSass.dir_for(:view) / :stylesheets
13
+ unless File.directory? template_dir
14
+ FileUtils.mkdir_p template_dir
15
+ end
16
+
17
+ # Create a template file
18
+ @store.send :write_file, @file, <<-CONTENT
19
+ h1
20
+ color: red
21
+ CONTENT
22
+ end
23
+
24
+ after(:all) do
25
+ FileUtils.rm @file
26
+ MerbDynamicSass.action_cache_store.delete("basic.css")
27
+ end
28
+
29
+ unless Merb::Slices.config[:merb_dynamic_sass][:page_cache]
30
+
31
+ it "should be successful and return a appropriate content-type header." do
32
+ response = request("/stylesheets/basic.css")
33
+ response.status.should be_successful
34
+ response.headers["Content-Type"].should == "text/css"
35
+
36
+ # doing twice to see the case when the cached file is exists.
37
+ response = request("/stylesheets/basic.css")
38
+ response.status.should be_successful
39
+ response.headers["Content-Type"].should == "text/css"
40
+ end
41
+
42
+
43
+ it "should let Stylesheets controller to receive filename" do
44
+ request_to("/stylesheets/some.css")[:path].should == "some"
45
+ end
46
+
47
+ it "should recognize filepath of requested stylesheets" do
48
+ request_to("/stylesheets/some_dir/some.css")[:path].should == "some_dir/some"
49
+ end
50
+
51
+ it "should cache generated stylesheets" do
52
+ response = request("/stylesheets/basic.css")
53
+ MerbDynamicSass.action_cache_store.should be_exists("basic.css")
54
+ end
55
+
56
+ it "should not use cahce if template is modified" do
57
+ store = @store
58
+ file = MerbDynamicSass.dir_for(:view) / :stylesheets / "modify.css.erb"
59
+
60
+ # Create a template file
61
+ store.send :write_file, file, <<-CONTENT
62
+ h1
63
+ color: red
64
+ CONTENT
65
+
66
+ # Caching
67
+ response = request("/stylesheets/modify.css")
68
+ response.should be_successful
69
+ store.exists?("modify.css").should == true
70
+ first_cache_modified_time = File.mtime(store.pathify("modify.css"))
71
+ store.read("modify.css").should include("color: red")
72
+
73
+ # Cached result should be used.
74
+ response = request("/stylesheets/modify.css")
75
+ response.should be_successful
76
+ File.mtime(store.pathify("modify.css")).should == first_cache_modified_time
77
+
78
+ sleep(2)
79
+
80
+ # Modify
81
+ store.send :write_file, file, <<-CONTENT
82
+ h1
83
+ color: green
84
+ CONTENT
85
+
86
+ # Caching again
87
+ response = request("/stylesheets/modify.css")
88
+ response.should be_successful
89
+ store.exists?("modify.css").should == true
90
+ second_cache_modified_time = File.mtime(store.pathify("modify.css"))
91
+ second_cache_modified_time.should > first_cache_modified_time
92
+ store.read("modify.css").should include("color: green")
93
+
94
+ store.delete("modify.css")
95
+ FileUtils.rm(file)
96
+
97
+ end
98
+
99
+
100
+ else
101
+
102
+ it "should have cache under Merb.root/:public if you need" do
103
+ Merb::Slices::config[:merb_dynamic_sass][:page_cache] = true
104
+ uri = "/stylesheets/basic.css"
105
+ response = request(uri, "REQUEST_URI" => uri)
106
+ response.status.should be_successful
107
+ response.headers["Content-Type"].should == "text/css"
108
+ cachefile = Merb.root_path( :public / :stylesheets / "basic.css" )
109
+ File.exists?(cachefile).should == true
110
+ FileUtils.rm(cachefile)
111
+ Merb::Slices::config[:merb_dynamic_sass][:page_cache] = false
112
+ end
113
+
114
+ end
115
+
116
+
117
+ end
@@ -0,0 +1,64 @@
1
+ require 'rubygems'
2
+ require 'merb-core'
3
+ require 'merb-slices'
4
+ require "merb-action-args"
5
+ require 'spec'
6
+
7
+ # Add merb_dynamic_sass.rb to the search path
8
+ Merb::Plugins.config[:merb_slices][:auto_register] = true
9
+ Merb::Plugins.config[:merb_slices][:search_path] = File.join(File.dirname(__FILE__), '..', 'lib', 'merb_dynamic_sass.rb')
10
+
11
+ Merb::Slices.config[:merb_dynamic_sass] = {
12
+ :page_cache => false
13
+ #:page_cache => true
14
+ }
15
+ # Require merb_dynamic_sass.rb explicitly so any dependencies are loaded
16
+ require Merb::Plugins.config[:merb_slices][:search_path]
17
+
18
+
19
+ # Using Merb.root below makes sure that the correct root is set for
20
+ # - testing standalone, without being installed as a gem and no host application
21
+ # - testing from within the host application; its root will be used
22
+ Merb.start_environment(
23
+ :testing => true,
24
+ :adapter => 'runner',
25
+ :environment => ENV['MERB_ENV'] || 'test',
26
+ :session_store => 'memory'
27
+ )
28
+
29
+ module Merb
30
+ module Test
31
+ module SliceHelper
32
+
33
+ # The absolute path to the current slice
34
+ def current_slice_root
35
+ @current_slice_root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
36
+ end
37
+
38
+ # Whether the specs are being run from a host application or standalone
39
+ def standalone?
40
+ Merb.root == ::MerbDynamicSass.root
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+
47
+ Spec::Runner.configure do |config|
48
+ config.include(Merb::Test::ViewHelper)
49
+ config.include(Merb::Test::RouteHelper)
50
+ config.include(Merb::Test::ControllerHelper)
51
+ config.include(Merb::Test::SliceHelper)
52
+ end
53
+
54
+ # You can add your own helpers here
55
+ #
56
+ Merb::Test.add_helpers do
57
+ def mount_slice
58
+ MerbDynamicSass.init if standalone?
59
+ end
60
+
61
+ def dismount_slice
62
+ Merb::Router.reset! if standalone?
63
+ end
64
+ end
@@ -0,0 +1,2 @@
1
+ class MerbDynamicSass::Application < Merb::Controller
2
+ end
@@ -0,0 +1,2 @@
1
+ class MerbDynamicSass::Main < MerbDynamicSass::Application
2
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: genki-merb_dynamic_sass
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Yukiko Kawamoto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-26 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb-slices
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: merb-cache
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.9
34
+ version:
35
+ description: Merb Dynamic Sass is a Merb Slice that provides more handy way to use Sass engine.
36
+ email: yu0420@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README
43
+ - LICENSE
44
+ - TODO
45
+ files:
46
+ - LICENSE
47
+ - README
48
+ - Rakefile
49
+ - TODO
50
+ - lib/merb_dynamic_sass
51
+ - lib/merb_dynamic_sass/merbtasks.rb
52
+ - lib/merb_dynamic_sass/slicetasks.rb
53
+ - lib/merb_dynamic_sass/spectasks.rb
54
+ - lib/merb_dynamic_sass.rb
55
+ - spec/merb_dynamic_sass_spec.rb
56
+ - spec/requests
57
+ - spec/requests/stylesheets_spec.rb
58
+ - spec/spec_helper.rb
59
+ - app/controllers
60
+ - app/controllers/application.rb
61
+ - app/controllers/stylesheets.rb
62
+ - app/helpers
63
+ - app/helpers/application_helper.rb
64
+ - app/views
65
+ - app/views/layout
66
+ - app/views/layout/merb_dynamic_sass.html.erb
67
+ - public/javascripts
68
+ - public/javascripts/master.js
69
+ - public/stylesheets
70
+ - public/stylesheets/master.css
71
+ - stubs/app
72
+ - stubs/app/controllers
73
+ - stubs/app/controllers/application.rb
74
+ - stubs/app/controllers/main.rb
75
+ has_rdoc: true
76
+ homepage: http://github.com/yukiko
77
+ post_install_message:
78
+ rdoc_options: []
79
+
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ requirements: []
95
+
96
+ rubyforge_project: merb
97
+ rubygems_version: 1.2.0
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Merb Dynamic Sass is a Merb Slice that provides more handy way to use Sass engine.
101
+ test_files: []
102
+