yukiko-merb_dynamic_sass 0.0.2

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.2"
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,66 @@
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
+ # TODO the rest is that prividing the way to generate file under the document root
26
+ # by useing slice.page_cache_store.
27
+ def index
28
+ @template_path = params[:path]
29
+ if self.slice.action_cache_store.exists?(_cache_path)
30
+
31
+ m_template = File.mtime _location_of_template
32
+ m_cache = File.mtime _location_of_cache
33
+
34
+ if m_template > m_cache
35
+ self.slice.action_cache_store.delete _cache_path
36
+ end
37
+
38
+ end
39
+
40
+ self.slice.action_cache_store.fetch _cache_path do
41
+ sass = render(:format => :css)
42
+ Sass::Engine.new(sass).to_css
43
+ end
44
+ end
45
+
46
+ def _cache_path
47
+ "#{@template_path}.css"
48
+ end
49
+ private :_cache_path
50
+
51
+ def _location_of_template
52
+ file = nil
53
+ self.class._template_roots.reverse_each do |root, template_method|
54
+ f = root / self.send(template_method, @template_path, :css, nil)
55
+ file = "#{f}.erb" and break if File.exists?("#{f}.erb")
56
+ end
57
+ file
58
+ end
59
+ private :_location_of_template
60
+
61
+ def _location_of_cache
62
+ self.slice.action_cache_store.pathify _cache_path
63
+ end
64
+ private :_location_of_cache
65
+
66
+ 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,110 @@
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
+ self.description = "MerbDynamicSass is a slice to provide more handy way to use Sass engine."
26
+ self.version = "0.0.1"
27
+ self.author = "Yukiko Kawamoto"
28
+
29
+ # Stub classes loaded hook - runs before LoadClasses BootLoader
30
+ # right after a slice's classes have been loaded internally.
31
+ def self.loaded
32
+ end
33
+
34
+ # Initialization hook - runs before AfterAppLoads BootLoader
35
+ # * use @initialized because sometimes self.init is called twice,
36
+ # especially during the spec or rake process.
37
+ attr_reader :initialized
38
+ def self.init
39
+ unless @initialized
40
+ require "sass"
41
+ # route is automatically prepared.
42
+ Merb::Router.prepare [], Merb::Router.routes do
43
+ slice(:merb_dynamic_sass, :name_prefix => nil)
44
+ end
45
+ Merb.add_mime_type(:css, :to_css, %w[text/css])
46
+ Merb.cache.register(action_cache_store_name, Merb::Cache::FileStore, :dir => Merb.root_path( :tmp / :cache / :stylesheets ))
47
+ Merb.cache.register(page_cache_store_name, Merb::Cache::PageStore[Merb::Cache::FileStore], :dir => Merb.root_path( "public" ))
48
+ @initialized = true
49
+ end
50
+ end
51
+
52
+ # Activation hook - runs after AfterAppLoads BootLoader
53
+ def self.activate
54
+ end
55
+
56
+ # Deactivation hook - triggered by Merb::Slices.deactivate(MerbDynamicSass)
57
+ def self.deactivate
58
+ end
59
+
60
+ # Setup routes inside the host application
61
+ #
62
+ # @param scope<Merb::Router::Behaviour>
63
+ # Routes will be added within this scope (namespace). In fact, any
64
+ # router behaviour is a valid namespace, so you can attach
65
+ # routes at any level of your router setup.
66
+ #
67
+ # @note prefix your named routes with :merb_dynamic_sass_
68
+ # to avoid potential conflicts with global named routes.
69
+ def self.setup_router(scope)
70
+ # example of a named route
71
+ scope.match(%r{^/stylesheets/(.*)\.css$}).to(:controller => "stylesheets", :action => "index", :path => "[1]").name :css
72
+ end
73
+
74
+ def self.action_cache_store_name
75
+ :dynamic_sass_action_cache
76
+ end
77
+
78
+ def self.page_cache_store_name
79
+ :dynamic_sass_page_cache
80
+ end
81
+
82
+ def self.action_cache_store
83
+ Merb::Cache[action_cache_store_name]
84
+ end
85
+
86
+ def self.page_cache_store
87
+ Merb::Cache[page_cache_store_name]
88
+ end
89
+
90
+ end
91
+
92
+ # Setup the slice layout for MerbDynamicSass
93
+ #
94
+ # Use MerbDynamicSass.push_path and MerbDynamicSass.push_app_path
95
+ # to set paths to merb_dynamic_sass-level and app-level paths. Example:
96
+ #
97
+ # MerbDynamicSass.push_path(:application, MerbDynamicSass.root)
98
+ # MerbDynamicSass.push_app_path(:application, Merb.root / 'slices' / 'merb_dynamic_sass')
99
+ # ...
100
+ #
101
+ # Any component path that hasn't been set will default to MerbDynamicSass.root
102
+ #
103
+ # Or just call setup_default_structure! to setup a basic Merb MVC structure.
104
+ MerbDynamicSass.setup_default_structure!
105
+
106
+ # Add dependencies for other MerbDynamicSass classes below. Example:
107
+ # dependency "merb_dynamic_sass/other"
108
+ dependency "merb-cache"
109
+
110
+ end
@@ -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
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,106 @@
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
+ # Create a template file
12
+ @store.send :write_file, @file, <<-CONTENT
13
+ h1
14
+ color: red
15
+ CONTENT
16
+ end
17
+
18
+ after(:all) do
19
+ FileUtils.rm @file
20
+ MerbDynamicSass.action_cache_store.delete("basic.css")
21
+ end
22
+
23
+ unless Merb::Slices.config[:merb_dynamic_sass][:page_cache]
24
+
25
+ it "should be successful and return a appropriate content-type header." do
26
+ response = request("/stylesheets/basic.css")
27
+ response.status.should be_successful
28
+ response.headers["Content-Type"].should == "text/css"
29
+ end
30
+
31
+
32
+ it "should let Stylesheets controller to receive filename" do
33
+ request_to("/stylesheets/some.css")[:path].should == "some"
34
+ end
35
+
36
+ it "should recognize filepath of requested stylesheets" do
37
+ request_to("/stylesheets/some_dir/some.css")[:path].should == "some_dir/some"
38
+ end
39
+
40
+ it "should cache generated stylesheets" do
41
+ response = request("/stylesheets/basic.css")
42
+ MerbDynamicSass.action_cache_store.should be_exists("basic.css")
43
+ end
44
+
45
+ it "should not use cahce if template is modified" do
46
+ store = @store
47
+ file = MerbDynamicSass.dir_for(:view) / :stylesheets / "modify.css.erb"
48
+
49
+ # Create a template file
50
+ store.send :write_file, file, <<-CONTENT
51
+ h1
52
+ color: red
53
+ CONTENT
54
+
55
+ # Caching
56
+ response = request("/stylesheets/modify.css")
57
+ response.should be_successful
58
+ store.exists?("modify.css").should == true
59
+ first_cache_modified_time = File.mtime(store.pathify("modify.css"))
60
+ store.read("modify.css").should include("color: red")
61
+
62
+ # Cached result should be used.
63
+ response = request("/stylesheets/modify.css")
64
+ response.should be_successful
65
+ File.mtime(store.pathify("modify.css")).should == first_cache_modified_time
66
+
67
+ sleep(2)
68
+
69
+ # Modify
70
+ store.send :write_file, file, <<-CONTENT
71
+ h1
72
+ color: green
73
+ CONTENT
74
+
75
+ # Caching again
76
+ response = request("/stylesheets/modify.css")
77
+ response.should be_successful
78
+ store.exists?("modify.css").should == true
79
+ second_cache_modified_time = File.mtime(store.pathify("modify.css"))
80
+ second_cache_modified_time.should > first_cache_modified_time
81
+ store.read("modify.css").should include("color: green")
82
+
83
+ store.delete("modify.css")
84
+ FileUtils.rm(file)
85
+
86
+ end
87
+
88
+
89
+ else
90
+
91
+ it "should have cache under Merb.root/:public if you need" do
92
+ Merb::Slices::config[:merb_dynamic_sass][:page_cache] = true
93
+ uri = "/stylesheets/basic.css"
94
+ response = request(uri, "REQUEST_URI" => uri)
95
+ response.status.should be_successful
96
+ response.headers["Content-Type"].should == "text/css"
97
+ cachefile = Merb.root_path( :public / :stylesheets / "basic.css" )
98
+ File.exists?(cachefile).should == true
99
+ FileUtils.rm(cachefile)
100
+ Merb::Slices::config[:merb_dynamic_sass][:page_cache] = false
101
+ end
102
+
103
+ end
104
+
105
+
106
+ 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,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yukiko-merb_dynamic_sass
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Yukiko Kawamoto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-21 00:00:00 -08: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.rb
51
+ - lib/merb_dynamic_sass
52
+ - lib/merb_dynamic_sass/slicetasks.rb
53
+ - lib/merb_dynamic_sass/merbtasks.rb
54
+ - lib/merb_dynamic_sass/spectasks.rb
55
+ - spec/requests
56
+ - spec/requests/stylesheets_spec.rb
57
+ - spec/spec_helper.rb
58
+ - spec/merb_dynamic_sass_spec.rb
59
+ - app/helpers
60
+ - app/helpers/application_helper.rb
61
+ - app/controllers
62
+ - app/controllers/stylesheets.rb
63
+ - app/controllers/application.rb
64
+ - app/views
65
+ - app/views/layout
66
+ - app/views/layout/merb_dynamic_sass.html.erb
67
+ - app/views/stylesheets
68
+ - public/stylesheets
69
+ - public/stylesheets/master.css
70
+ - public/javascripts
71
+ - public/javascripts/master.js
72
+ - stubs/app
73
+ - stubs/app/controllers
74
+ - stubs/app/controllers/main.rb
75
+ - stubs/app/controllers/application.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/yukiko
78
+ post_install_message:
79
+ rdoc_options: []
80
+
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ requirements: []
96
+
97
+ rubyforge_project: merb
98
+ rubygems_version: 1.2.0
99
+ signing_key:
100
+ specification_version: 2
101
+ summary: Merb Dynamic Sass is a Merb Slice that provides more handy way to use Sass engine.
102
+ test_files: []
103
+