capcode-render-haml 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 glejeune
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.
@@ -0,0 +1,3 @@
1
+ = capcode-render-haml
2
+
3
+ Capcode plugin to render via Haml
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "capcode-render-haml"
8
+ gem.summary = %Q{Capcode plugin to render via Haml}
9
+ gem.description = gem.summary
10
+ gem.email = "gregoire.lejeune@free.fr"
11
+ gem.homepage = "http://github.com/glejeune/Capcode.more/tree/master/%s" % gem.name
12
+ gem.authors = ["Gregoire Lejeune"]
13
+
14
+ gem.add_dependency('haml')
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,49 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{capcode-render-haml}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Gregoire Lejeune"]
12
+ s.date = %q{2010-01-06}
13
+ s.description = %q{Capcode plugin to render via Haml}
14
+ s.email = %q{gregoire.lejeune@free.fr}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "capcode-render-haml.gemspec",
24
+ "examples/haml/cf.haml",
25
+ "examples/haml/cf_layout.haml",
26
+ "examples/haml/style.sass",
27
+ "examples/render-haml_sass.rb",
28
+ "lib/capcode/render/haml.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/glejeune/Capcode.more/tree/master/capcode-render-haml}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.5}
34
+ s.summary = %q{Capcode plugin to render via Haml}
35
+
36
+ if s.respond_to? :specification_version then
37
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
41
+ s.add_runtime_dependency(%q<haml>, [">= 0"])
42
+ else
43
+ s.add_dependency(%q<haml>, [">= 0"])
44
+ end
45
+ else
46
+ s.add_dependency(%q<haml>, [">= 0"])
47
+ end
48
+ end
49
+
@@ -0,0 +1,7 @@
1
+ - content_for( :header ) do
2
+ %title This is the title!
3
+ - content_for( :content ) do
4
+ %p this is the content!
5
+ %p
6
+ Time :
7
+ = @time
@@ -0,0 +1,6 @@
1
+ %html
2
+ %head
3
+ = yield :header
4
+ %link{ :rel => "stylesheet", :href => "/style.css", :type => "text/css" }
5
+ %body
6
+ = yield :content
@@ -0,0 +1,2 @@
1
+ p
2
+ background-color: red
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'capcode'
3
+ require 'capcode/render/sass'
4
+ $:.unshift( "../lib" )
5
+ require 'capcode/render/haml'
6
+
7
+ module Capcode
8
+ set :haml, "haml" #, { :format => :html4 }
9
+ set :sass, "haml"
10
+
11
+ class Index < Route '/'
12
+ def get
13
+ @time = Time.now
14
+ render :haml => :cf, :layout => :cf_layout
15
+ end
16
+ end
17
+
18
+ class CSS < Route '/style.css'
19
+ def get
20
+ render :sass => :style
21
+ end
22
+ end
23
+ end
24
+
25
+ Capcode.run( )
@@ -0,0 +1,63 @@
1
+ begin
2
+ require 'haml'
3
+ rescue LoadError => e
4
+ raise MissingLibrary, "Haml could not be loaded (is it installed?): #{e.message}"
5
+ end
6
+
7
+ module Capcode
8
+ module Helpers
9
+ # Set the path to Haml files. If this path is not set, Capcode will search in the static path.
10
+ # This method is deprecated and will be removed in version 1.0
11
+ def self.haml_path=( p )
12
+ warn "Capcode::Helpers.haml_path is deprecated and will be removed in version 1.0, please use `set :haml'"
13
+ Capcode::Configuration.set :haml, p
14
+ end
15
+
16
+ def render_haml( f, opts = {} ) #:nodoc:
17
+ if @haml_path.nil?
18
+ @haml_path = Capcode::Configuration.get( :haml ) || Capcode.static()
19
+ end
20
+
21
+ f = f.to_s
22
+ if f.include? '..'
23
+ return [403, {}, '403 - Invalid path']
24
+ end
25
+
26
+ if /Windows/.match( ENV['OS'] )
27
+ unless( /.:\\/.match( @haml_path[0] ) )
28
+ @haml_path = File.expand_path( File.join(".", @haml_path) )
29
+ end
30
+ else
31
+ unless( @haml_path[0].chr == "/" )
32
+ @haml_path = File.expand_path( File.join(".", @haml_path) )
33
+ end
34
+ end
35
+
36
+ # Update options
37
+ opts = (Capcode.options[:haml] || {}).merge(opts)
38
+
39
+ # Get Layout file
40
+ layout = opts.delete(:layout)||:layout
41
+ layout_file = File.join( @haml_path, layout.to_s+".haml" )
42
+
43
+ # Get HAML File
44
+ f = f + ".haml" if File.extname( f ) != ".haml"
45
+ file = File.join( @haml_path, f )
46
+
47
+ # Render
48
+ if( File.exist?( file ) )
49
+ if( File.exist?( layout_file ) )
50
+ Haml::Engine.new( open( layout_file ).read, opts ).to_html(self) { |*args|
51
+ #@@__ARGS__ = args
52
+ Capcode::Helpers.args = args
53
+ Haml::Engine.new( open( file ).read ).render(self)
54
+ }
55
+ else
56
+ Haml::Engine.new( open( file ).read, opts ).to_html( self )
57
+ end
58
+ else
59
+ raise Capcode::RenderError, "Error rendering `haml', #{file} does not exist !"
60
+ end
61
+ end
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capcode-render-haml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gregoire Lejeune
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-06 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: haml
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Capcode plugin to render via Haml
26
+ email: gregoire.lejeune@free.fr
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - VERSION
38
+ - capcode-render-haml.gemspec
39
+ - examples/haml/cf.haml
40
+ - examples/haml/cf_layout.haml
41
+ - examples/haml/style.sass
42
+ - examples/render-haml_sass.rb
43
+ - lib/capcode/render/haml.rb
44
+ has_rdoc: true
45
+ homepage: http://github.com/glejeune/Capcode.more/tree/master/capcode-render-haml
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Capcode plugin to render via Haml
72
+ test_files: []
73
+