tipsy 0.0.2 → 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.
Files changed (95) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +6 -11
  3. data/README.md +24 -1
  4. data/Rakefile +13 -9
  5. data/bin/tipsy +4 -2
  6. data/lib/templates/server/htaccess.erb +14 -0
  7. data/lib/templates/site/Gemfile +19 -0
  8. data/lib/templates/site/assets/stylesheets/_config.css.scss +1 -0
  9. data/lib/templates/site/assets/stylesheets/screen.css.scss +1 -0
  10. data/lib/templates/site/config.rb +52 -0
  11. data/lib/templates/site/deploy.yml +27 -0
  12. data/lib/templates/site/layouts/default.html.erb +41 -0
  13. data/lib/templates/site/views/index.html.erb +2 -0
  14. data/lib/tipsy/compressors/{css.rb → css_compressor.rb} +0 -0
  15. data/lib/tipsy/compressors/javascript_compressor.rb +44 -0
  16. data/lib/tipsy/configuration.rb +9 -0
  17. data/lib/tipsy/handler/all.rb +4 -0
  18. data/lib/tipsy/handler/asset.rb +93 -0
  19. data/lib/tipsy/handler/erb.rb +42 -0
  20. data/lib/tipsy/handler/php.rb +36 -0
  21. data/lib/tipsy/{sass/template.rb → handler/sass/importer.rb} +15 -53
  22. data/lib/tipsy/handler/sass/resolver.rb +30 -0
  23. data/lib/tipsy/handler/sass.rb +36 -0
  24. data/lib/tipsy/handler/static.rb +30 -0
  25. data/lib/tipsy/helpers/asset_paths.rb +29 -1
  26. data/lib/tipsy/helpers/asset_tags.rb +1 -1
  27. data/lib/tipsy/helpers/capture.rb +12 -41
  28. data/lib/tipsy/helpers/rendering.rb +46 -0
  29. data/lib/tipsy/helpers/sass.rb +17 -6
  30. data/lib/tipsy/helpers/tag.rb +6 -9
  31. data/lib/tipsy/helpers.rb +13 -16
  32. data/lib/tipsy/runner.rb +82 -0
  33. data/lib/tipsy/runners/compiler.rb +189 -0
  34. data/lib/tipsy/runners/deployer.rb +7 -0
  35. data/lib/tipsy/runners/generator.rb +24 -0
  36. data/lib/tipsy/server.rb +56 -114
  37. data/lib/tipsy/site.rb +88 -0
  38. data/lib/tipsy/utils/logger.rb +47 -0
  39. data/lib/tipsy/utils/system.rb +115 -0
  40. data/lib/tipsy/utils/system_test.rb +103 -0
  41. data/lib/tipsy/version.rb +1 -1
  42. data/lib/tipsy/view/base.rb +55 -0
  43. data/lib/tipsy/view/context.rb +28 -0
  44. data/lib/tipsy/view/path.rb +44 -0
  45. data/lib/tipsy/view.rb +14 -68
  46. data/lib/tipsy.rb +30 -67
  47. data/{lib/tipsy/project/assets/javascripts/site.js → test/fixtures/capture.html.erb} +0 -0
  48. data/test/helpers/tag_test.rb +22 -0
  49. data/{lib/tipsy/project/assets/stylesheets/screen.css.scss → test/root/compiled/fake.txt} +0 -0
  50. data/test/root/{test/assets/javascripts/test.js → compiled/sub-path/fake.txt} +0 -0
  51. data/test/root/{development/assets/javascripts/test.js → compiled/sub-path-with-skip/fake.txt} +0 -0
  52. data/test/root/layouts/default.html.erb +0 -0
  53. data/test/root/views/index.html.erb +0 -0
  54. data/test/root/views/page.html.erb +0 -0
  55. data/test/root/views/sub/page.html.erb +0 -0
  56. data/test/root/views/sub/tertiary/index.html.erb +0 -0
  57. data/test/runner/compiler_test.rb +49 -0
  58. data/test/test_helper.rb +160 -21
  59. data/test/unit/site_test.rb +23 -0
  60. data/test/unit/tipsy_test.rb +13 -0
  61. data/test/unit/utils/system_test.rb +26 -0
  62. data/test/view/base_test.rb +34 -0
  63. data/test/view/path_test.rb +34 -0
  64. data/tipsy.gemspec +10 -7
  65. metadata +113 -84
  66. data/lib/tipsy/application.rb +0 -86
  67. data/lib/tipsy/builder.rb +0 -26
  68. data/lib/tipsy/builders/base.rb +0 -64
  69. data/lib/tipsy/builders/export.rb +0 -16
  70. data/lib/tipsy/builders/project.rb +0 -40
  71. data/lib/tipsy/builders/remote.rb +0 -14
  72. data/lib/tipsy/compressors/javascript.rb +0 -25
  73. data/lib/tipsy/logger.rb +0 -62
  74. data/lib/tipsy/project/Gemfile +0 -8
  75. data/lib/tipsy/project/config.erb +0 -19
  76. data/lib/tipsy/project/helpers/site_helper.rb +0 -4
  77. data/lib/tipsy/project/views/_layout.html.erb +0 -16
  78. data/test/fixtures/about.html +0 -1
  79. data/test/fixtures/contact.html +0 -1
  80. data/test/fixtures/index.html +0 -1
  81. data/test/functional/page_test.rb +0 -33
  82. data/test/root/.gitignore +0 -7
  83. data/test/root/development/assets/stylesheets/screen.css.scss +0 -3
  84. data/test/root/development/config.rb +0 -6
  85. data/test/root/development/views/_layout.html.erb +0 -20
  86. data/test/root/development/views/index.html.erb +0 -3
  87. data/test/root/test/assets/stylesheets/screen.css.scss +0 -3
  88. data/test/root/test/config.rb +0 -6
  89. data/test/root/test/views/_layout.html.erb +0 -1
  90. data/test/root/test/views/about/index.html +0 -1
  91. data/test/root/test/views/contact.html +0 -1
  92. data/test/root/test/views/index.html.erb +0 -1
  93. data/test/unit/helpers/asset_paths_test.rb +0 -14
  94. data/test/unit/helpers_test.rb +0 -22
  95. data/test/unit/server_test.rb +0 -1
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ pkg/*
5
5
  .DS_Store
6
6
  .rvmrc
7
7
  .sass-cache/*
8
+ old/*
data/Gemfile CHANGED
@@ -1,14 +1,9 @@
1
1
  source "http://rubygems.org"
2
- gemspec
3
2
 
4
- gem 'facades', :path => '/_Work/gems/facades'
5
- gem 'thin'
3
+ # Specify your gem's dependencies in tipsy.gemspec
4
+ gemspec
6
5
 
7
- group :test do
8
- gem 'jnunemaker-matchy', '~> 0.4.0', :require => 'matchy'
9
- gem 'shoulda', '~> 2.11'
10
- gem 'mocha', '~> 0.9.12'
11
- gem 'rack-test'
12
- gem 'turn'
13
- gem 'minitest'
14
- end
6
+ gem 'compass', '~> 0.12.alpha0'
7
+ gem 'colored'
8
+ gem 'rspec'
9
+ gem 'rspec-expectations'
data/README.md CHANGED
@@ -4,7 +4,30 @@ Tipsy is a small Rack-based server inspired by gems like StaticMatic and Serve.
4
4
  Rails-esque style templating and helpers. Various template types are supported via the Tilt gem, and assets are served via Sprockets, essentially giving you
5
5
  a miniture Rails "view-only" environment.
6
6
 
7
+ Any template format Tilt provides should work without much hassle. ERB (via Erubis) is provided. Note Erubis is required to make ERB function properly as
8
+ we've applied some of the same modifications as Rails, allowing things like block style helpers such as
9
+
10
+ <%= capture do %>
11
+ something
12
+ <% end %>
13
+
14
+ which would error normally. By doing so it should make integration with any number of ActionView style helpers fairly simple.
15
+
16
+ ## Usage
17
+
18
+ **Creating** To create a new site run `tipsy new name_of_site` to generate a new site in the current directory.
19
+
20
+ **Compiling** To compile the site into a production-ready state, run `tipsy compile` from the site's root directory.
21
+
22
+ **Serving** Simply run `tipsy` from the site root. Its recommended to add Thin or Mongrel to your Gemfile but Webrick will be used as a fallback.
23
+
24
+ Running the site generator should provide all of the configuration and setup options you would need to get started. Check out config.rb in the created
25
+ site's root for more info.
26
+
7
27
  ### Notes
8
28
 
9
29
  Tipsy was developed for personal/internal use but feature/pull requests are gladly accepted. It is not designed to function in any kind of production
10
- environment. When ready to upload files to a production environment, build the project and upload the result.
30
+ environment. When ready to upload files to a production environment, build the project and upload the result.
31
+
32
+ By default *most* ActionView compatible helpers should work out of the box... with the exception of helpers extending things like the form builder etc.
33
+ Right now Tipsy has no form builder, so you would have to provide your own.
data/Rakefile CHANGED
@@ -1,11 +1,15 @@
1
- require 'rake'
2
- require 'bundler/gem_tasks'
3
- require 'rake/testtask'
1
+ #!/usr/bin/env rake
2
+ $:.unshift File.expand_path('.', __FILE__)
3
+
4
+ require 'rubygems'
5
+ require 'bundler'
6
+ Bundler::GemHelper.install_tasks
4
7
 
5
- Rake::TestTask.new(:test) do |test|
6
- test.libs << 'lib' << 'test'
7
- test.pattern = 'test/**/*_test.rb'
8
- test.verbose = true
9
- end
8
+ require 'rake/testtask'
10
9
 
11
- task :default => :test
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.test_files = FileList['test/**/*_test.rb']
12
+ t.libs << 'lib'
13
+ t.libs << 'test'
14
+ t.verbose = true
15
+ end
data/bin/tipsy CHANGED
@@ -5,6 +5,8 @@ if File.file?(libdir + '/tipsy/version.rb')
5
5
  $LOAD_PATH.unshift(libdir)
6
6
  end
7
7
 
8
+ ENV['TIPSY_ROOT'] ||= File.expand_path('.')
9
+
8
10
  begin
9
11
  require 'tipsy'
10
12
  rescue LoadError
@@ -17,5 +19,5 @@ if File.exists?(File.join(File.expand_path('.'), 'Gemfile'))
17
19
  Bundler.require(:default)
18
20
  end
19
21
 
20
- Tipsy.root = File.expand_path('.')
21
- Tipsy.run_command(ARGV, STDIN)
22
+ require 'tipsy/runner'
23
+ Tipsy::Runner.new(ARGV, STDIN)
@@ -0,0 +1,14 @@
1
+ ##################################################################
2
+ # Basic rewriting to avoid file extensions where the
3
+ # result is a basic html page.
4
+ ##################################################################
5
+
6
+ # For IE .htc files
7
+ AddType text/x-component .htc
8
+
9
+ RewriteEngine on
10
+ RewriteBase /
11
+
12
+ RewriteCond %{REQUEST_FILENAME} !-f
13
+ RewriteCond %{REQUEST_FILENAME} !-d
14
+ RewriteRule ^(.*)$ $1.html [L,QSA]
@@ -0,0 +1,19 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rack", "~> 1.3"
4
+ gem "tilt", "~> 1.3"
5
+ gem "i18n", "~> 0.6"
6
+ gem "sass", "~> 3.1"
7
+ gem "activesupport", ">= 3.1"
8
+ gem "sprockets", "~> 2.0"
9
+ gem "erubis"
10
+
11
+ # Thin or mongrel are recommended over Webrick
12
+ # gem "thin"
13
+
14
+ # Uglifier is recommended for javascript compression. If unavailable, Google's online
15
+ # closure compiler will be used.
16
+ # gem 'uglifier'
17
+
18
+ # Compass is automatically detected and configured if available
19
+ # gem "compass", "~> 0.11"
@@ -0,0 +1 @@
1
+ // Setup global variables etc here.
@@ -0,0 +1 @@
1
+ @import 'config';
@@ -0,0 +1,52 @@
1
+ # Configure urls where assets are to be served.
2
+ # In development, assets should be placed under root_path/assets
3
+ # On compile, assets will be stored at these locations (defaults shown)
4
+ #
5
+ asset_path = "/assets"
6
+ javascripts_path = "/assets"
7
+ images_path = "/assets"
8
+ css_path = "/assets"
9
+
10
+ # Fonts don't really need to be served by sprockets, they should go in your public_path.
11
+ # This option is mostly provided for using asset_url helpers in Sass
12
+ fonts_path = "/fonts"
13
+
14
+ # On compile, use this folder. Accepts either a relative or absolute path
15
+ compile_to = "compiled"
16
+
17
+ # Static files and assets will be served from this location
18
+ public_path = "public"
19
+
20
+ # Configure assets to be compiled at compile-time (default: screen.css and site.js)
21
+ #
22
+ compile.assets << "site.js"
23
+ compile.assets << "screen.css"
24
+
25
+ # By default template compilation will generate files as they exist in your /views directory.
26
+ # This allows for rewriting via .htaccess or nginx config to avoid .html extensions in your urls.
27
+ # If you would prefer a folder/index.html structure for the resulting html files, set compile.enable_rewrite to false.
28
+ # Set compile.rewrite_mode to one of :nginx or :htaccess to have a .htaccess/nginx.conf file generated for you.
29
+ # The default configurations are shown below
30
+ #
31
+ # compile.enable_rewrite = true
32
+ # compile.rewrite_mode = :htaccess
33
+
34
+ # Compiling cleans the 'compile_to' path prior to re-building the site.
35
+ # To ensure certain directories are preserved, add them here. This is primarily useful for scm directories
36
+ #
37
+ # compile.preserve << ".svn"
38
+ #
39
+ # When compiling, all files and folders found in the 'public_path' are copied. To ignore
40
+ # specific files or folders, include them here.
41
+ #
42
+ # compile.skip << "some-path"
43
+ #
44
+ #
45
+ # Callbacks:
46
+ # To perform additional tasks either before or after compilation, define either a
47
+ # before_compile, after_compile, or both. Blocks are passed an instance of the Compiler.
48
+ # See tipsy/runners/compiler.rb for more info.
49
+ #
50
+ # after_compile do |runner|
51
+ # end
52
+ #
@@ -0,0 +1,27 @@
1
+ # Configure deployment options here.
2
+ # Only the default is required for deployment, specify separate locations as needed to
3
+ # deploy to multiple servers.
4
+ #
5
+ # Options:
6
+ # server_type: Either apache or nginx.
7
+ # scm: One of subversion, git, or simply false. (experimental)
8
+ # deploy_to: Where the deployed files should be placed.
9
+ # deploy_via: One of ftp, sftp, or ssh. For scm deployments, ssh is required. S3 support coming in a future release
10
+ #
11
+
12
+ defaults: &defaults
13
+ server_type: "apache"
14
+ scm: false
15
+ deploy_to: ""
16
+ deploy_via: "ftp"
17
+ port: 22
18
+ username: "deploy"
19
+
20
+ default:
21
+ <<: *defaults
22
+ host: "ftp.somewhere.com"
23
+
24
+ # setup a second location
25
+ #server2:
26
+ # <<: *defaults
27
+
@@ -0,0 +1,41 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <!-- pre-fetch dns info for external sites -->
6
+ <link rel="dns-prefetch" href="//ajax.googleapis.com" />
7
+ <!-- force IE to render as IE... weird isn't it? -->
8
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
9
+ <!-- 'pinned' sites in IE ( see: http://html5boilerplate.com/docs/head-Tips/ ) -->
10
+ <meta name="application-name" content="" />
11
+ <meta name="msapplication-tooltip" content="" />
12
+ <!-- Facebook open graph ( seff: http://developers.facebook.com/docs/share ) -->
13
+ <meta property="og:title" content="" />
14
+ <meta property="og:description" content="" />
15
+ <meta property="og:image" content="" />
16
+ <title><%= page_title %></title>
17
+ <meta name="description" content="" />
18
+ <meta name="author" content="" />
19
+ <meta name="viewport" content="width=device-width,initial-scale=1,target-densitydpi=device-dpi" />
20
+ <!--[if lt IE 9]>
21
+ <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
22
+ <%= stylesheet_link_tag 'ie' %>
23
+ <![endif]-->
24
+ <%= stylesheet_link_tag 'screen' %>
25
+ </head>
26
+ <body id="<%= page_id %>">
27
+ <div id="wrapper">
28
+ <header>
29
+
30
+ </header>
31
+ <div id="main" role="main">
32
+ <%= yield %>
33
+ </div>
34
+ <footer>
35
+
36
+ </footer>
37
+ </div>
38
+ <%= javascript_include_tag "//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" %>
39
+ <%= javascript_include_tag 'site' %>
40
+ </body>
41
+ </html>
@@ -0,0 +1,2 @@
1
+ <% page_id('home') %>
2
+ <% page_title('Your Home Page') %>
File without changes
@@ -0,0 +1,44 @@
1
+ ##
2
+ # Includes an interface to Google's Online Closure Compiler.
3
+ # Uglifier is recommended (gem install uglifier) however to support environments where Node.js
4
+ # is unavailable this can be used as a fallback.
5
+ #
6
+ require 'net/http'
7
+ require 'uri'
8
+
9
+ module Tipsy
10
+ module Compressors
11
+
12
+ module Closure
13
+ def compress(js)
14
+ return js if js.to_s.blank?
15
+ post_data = {
16
+ 'compilation_level' => 'SIMPLE_OPTIMIZATIONS',
17
+ 'js_code' => js.to_s,
18
+ 'output_format' => 'text'
19
+ }
20
+ request = Net::HTTP.post_form(URI.parse('http://closure-compiler.appspot.com/compile'), post_data)
21
+ request.body.to_s
22
+ end
23
+ end
24
+
25
+ module Uglifier
26
+ def compress(js)
27
+ ::Uglifier.compile(js, :max_line_length => 500, :squeeze => true, :copyright => false)
28
+ end
29
+ end
30
+
31
+ class JavascriptCompressor
32
+ def initialize
33
+ begin
34
+ require 'uglifier'
35
+ self.class.send(:include, Uglifier)
36
+ rescue LoadError
37
+ Tipsy.logger.info("Add the Uglifier gem to your gemfile for better javascript support")
38
+ self.class.send(:include, Closure)
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,9 @@
1
+ module Tipsy
2
+ class Configuration < ActiveSupport::OrderedHash
3
+
4
+ def initialize(*args)
5
+ super(*args)
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ Dir.glob(File.dirname(__FILE__) << "/*.rb").each do |path|
2
+ next if File.basename(path) == __FILE__
3
+ require path
4
+ end
@@ -0,0 +1,93 @@
1
+ require 'sprockets'
2
+ require 'hike'
3
+ require 'tipsy/handler/sass'
4
+
5
+ module Tipsy
6
+ module Handler
7
+ ##
8
+ # The AssetHandler is a subclass of Sprockets::Environment resposible for delivering
9
+ # assets back to the browser. In development assets should be defined under:
10
+ # javascripts: /assets/javascripts
11
+ # images: /assets/images
12
+ # stylesheets: /assets/stylesheets
13
+ #
14
+ # Configure delivery urls using Tipsy::Site.asset_path, or Tipsy::Site.type_path where 'type' is the type of asset to configure
15
+ # Although assets are stored in the /assets folder, when compiled these directories will be used for the final
16
+ # output. This way assets can be organized during development, but placed anywhere when deployed
17
+ #
18
+ class AssetHandler < ::Sprockets::Environment
19
+ attr_reader :asset_env
20
+
21
+ class << self
22
+ def map!
23
+ fpaths = [:javascripts_path, :css_path, :images_path].collect{ |p| File.basename(Tipsy::Site.send(p)) }
24
+ fpaths.inject({}) do |hash, path|
25
+ hash.merge!("/#{path}" => self.new)
26
+ end
27
+ end
28
+ end
29
+
30
+ def initialize
31
+ ::Sprockets.register_engine '.scss', Tipsy::Handler::SassHandler
32
+ super(Tipsy.root) do |env|
33
+ @asset_env = env
34
+ end
35
+ append_path "assets/javascripts"
36
+ append_path "assets/images"
37
+ append_path "assets/stylesheets"
38
+
39
+ configure_compass!
40
+ self
41
+
42
+ end
43
+
44
+ ##
45
+ # Setup compressors for compilation
46
+ #
47
+ def prepare_compiler
48
+ asset_env.css_compressor = Tipsy::Compressors::CssCompressor.new
49
+ asset_env.js_compressor = Tipsy::Compressors::JavascriptCompressor.new
50
+ end
51
+
52
+ ##
53
+ # When exceptions are thrown through Sprockets, ensure that the
54
+ # current indexes are expired. This ensures we never receive a CircularDependency error.
55
+ #
56
+ def javascript_exception_response(exception)
57
+ expire_index!
58
+ super(exception)
59
+ end
60
+
61
+ def css_exception_response(exception)
62
+ expire_index!
63
+ super(exception)
64
+ end
65
+
66
+ private
67
+
68
+ def configure_compass!
69
+ begin
70
+ require 'compass'
71
+ require 'sass/plugin'
72
+
73
+ compass_config = ::Compass::Configuration::Data.new("project")
74
+ compass_config.project_type = :stand_alone
75
+ compass_config.project_path = Tipsy.root
76
+ compass_config.images_dir = File.join('assets', 'images')
77
+ compass_config.sass_dir = File.join('assets', 'stylesheets')
78
+ compass_config.http_images_path = "/#{File.basename(Tipsy::Site.images_path)}"
79
+ compass_config.relative_assets = false
80
+ compass_config.line_comments = false
81
+
82
+ Compass.add_project_configuration(compass_config)
83
+ ::Sass::Plugin.engine_options.merge!(Compass.sass_engine_options)
84
+
85
+ rescue LoadError
86
+ require 'tipsy/helpers/sass'
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+ end
@@ -0,0 +1,42 @@
1
+ require "erubis"
2
+ ##
3
+ # The ErbHandler hacks erubis in the same manner as Rails.
4
+ # This allows support for Rails view helpers.
5
+ #
6
+ module Tipsy
7
+ module Handler
8
+ class ErbHandler < ::Tilt::ErubisTemplate
9
+ end
10
+ end
11
+ end
12
+
13
+ class Erubis::Eruby
14
+ def add_text(src, text)
15
+ return if text.empty? || text.nil?
16
+ src << "@output_buffer.concat('" << escape_text(text) << "');"
17
+ end
18
+
19
+ BLOCK_EXPR = /\s+(do|\{)(\s*\|[^|]*\|)?\s*\Z/
20
+
21
+ def add_expr_literal(src, code)
22
+ return if code.nil?
23
+ if code.to_s =~ BLOCK_EXPR
24
+ src << '@output_buffer << ' << code.to_s
25
+ else
26
+ src << '@output_buffer << (' << code.to_s << ');'
27
+ end
28
+ end
29
+
30
+ def add_expr_escaped(src, code)
31
+ return if code.nil?
32
+ if code.to_s =~ BLOCK_EXPR
33
+ src << "@output_buffer << " << code.to_s
34
+ else
35
+ src << "@output_buffer.concat((" << code.to_s << ").to_s);"
36
+ end
37
+ end
38
+
39
+ def add_postamble(src)
40
+ src << '@output_buffer.to_s'
41
+ end
42
+ end
@@ -0,0 +1,36 @@
1
+ require 'tilt'
2
+
3
+ module Tipsy
4
+ module Handler
5
+ ##
6
+ # The PHP engine allows processing/rendering of php templates within the server
7
+ # environment. To process php templates, use the template.html.php naming syntax.
8
+ #
9
+ class PhpHandler < Tilt::Template
10
+
11
+ self.default_mime_type = 'text/html'
12
+
13
+ def prepare
14
+ @engine = PhpProcessor.new(data)
15
+ end
16
+
17
+ def evaluate(scope, locals, &block)
18
+ @output ||= @engine.render
19
+ end
20
+ end
21
+
22
+ class PhpProcessor
23
+ attr_accessor :data
24
+
25
+ def initialize(d)
26
+ @data = d
27
+ end
28
+
29
+ def render
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+ Tilt.register(Tipsy::Handler::PhpHandler, 'php')
@@ -1,39 +1,13 @@
1
- require 'tilt'
2
- require 'sass/engine'
3
- require 'compass'
1
+ begin
2
+ require 'compass'
3
+ rescue LoadError
4
+ end
4
5
 
5
- ##
6
- # Most of this was extracted and modified from the sass-rails plugin, since most of the
7
- # Sprockets functionality is the same.
8
- #
9
6
  module Tipsy
10
- module Sass
11
- class Template < Tilt::ScssTemplate
12
- self.default_mime_type = 'text/css'
13
-
14
- class Resolver
15
- attr_accessor :context
16
- def initialize(context)
17
- @context = context
18
- end
19
- def resolve(path, content_type = :self)
20
- options = {}
21
- options[:content_type] = content_type unless content_type.nil?
22
- context.resolve(path, options)
23
- rescue Sprockets::FileNotFound, Sprockets::ContentTypeMismatch
24
- nil
25
- end
26
- def public_path(path, scope)
27
- context.asset_paths.compute_public_path(path, scope)
28
- end
29
- def process(path)
30
- context.environment[path].to_s
31
- end
32
- end
33
-
34
-
7
+ module Handler
8
+ class SassHandler < ::Tilt::ScssTemplate
35
9
  class Importer
36
-
10
+
37
11
  GLOB = /\*|\[.+\]/
38
12
  PARTIAL = /^_/
39
13
  HAS_EXTENSION = /\.css(.s[ac]ss)?$/
@@ -43,14 +17,14 @@ module Tipsy
43
17
  ".sass" => :sass,
44
18
  ".scss" => :scss
45
19
  }
46
-
20
+
47
21
  attr_reader :context
48
22
 
49
23
  def initialize(context)
50
24
  @context = context
51
25
  @resolver = Resolver.new(context)
52
26
  end
53
-
27
+
54
28
  def sass_file?(filename)
55
29
  filename = filename.to_s
56
30
  SASS_EXTENSIONS.keys.any?{|ext| filename[ext]}
@@ -61,7 +35,7 @@ module Tipsy
61
35
  SASS_EXTENSIONS.each {|ext, syntax| return syntax if filename[(ext.size+2)..-1][ext]}
62
36
  nil
63
37
  end
64
-
38
+
65
39
  def render_with_engine(data, pathname, options = {})
66
40
  ::Sass::Engine.new(data, options.merge(:filename => pathname.to_s, :importer => self, :syntax => syntax(pathname)))
67
41
  end
@@ -75,7 +49,7 @@ module Tipsy
75
49
  partial_name = name.dirname.join("_#{name.basename}")
76
50
  @resolver.resolve(name) || @resolver.resolve(partial_name)
77
51
  end
78
-
52
+
79
53
  def find_relative(name, base, options)
80
54
  base_pathname = Pathname.new(base)
81
55
  if pathname = resolve(name, base_pathname.dirname)
@@ -89,7 +63,7 @@ module Tipsy
89
63
  nil
90
64
  end
91
65
  end
92
-
66
+
93
67
  def find(name, options)
94
68
  if pathname = resolve(name)
95
69
  context.depend_on(pathname)
@@ -112,26 +86,14 @@ module Tipsy
112
86
  def key(name, options)
113
87
  ["Sprockets:" + File.dirname(File.expand_path(name)), File.basename(name)]
114
88
  end
115
-
89
+
116
90
  def resolve_sass_path(name, options = {}, relative = false)
117
91
  prefix = ( relative === false ? "" : "./" )
118
92
  (context.resolve("#{prefix}#{name}", options) || context.resolve("#{prefix}_#{name}", options))
119
93
  end
120
-
121
- end
122
-
123
- def prepare
94
+
124
95
  end
125
-
126
- def evaluate(scope, locals, &block)
127
- ::Sass::Engine.new(data, {
128
- :filename => eval_file,
129
- :line => line,
130
- :syntax => :scss,
131
- :importer => Importer.new(scope)
132
- }.reverse_merge!(::Compass.sass_engine_options)).render
133
- end
134
-
96
+
135
97
  end
136
98
  end
137
99
  end
@@ -0,0 +1,30 @@
1
+ module Tipsy
2
+ module Handler
3
+ class SassHandler < ::Tilt::ScssTemplate
4
+
5
+ class Resolver
6
+ attr_accessor :context
7
+
8
+ def initialize(context)
9
+ @context = context
10
+ end
11
+
12
+ def resolve(path, content_type = :self)
13
+ options = {}
14
+ options[:content_type] = content_type unless content_type.nil?
15
+ context.resolve(path, options)
16
+ rescue Sprockets::FileNotFound, Sprockets::ContentTypeMismatch
17
+ nil
18
+ end
19
+
20
+ def public_path(path, scope)
21
+ context.asset_paths.compute_public_path(path, scope)
22
+ end
23
+
24
+ def process(path)
25
+ context.environment[path].to_s
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end