rails-template-inheritance 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ /*.gem
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "examples"]
2
+ path = examples
3
+ url = git://github.com/botanicus/rango-in-rails.git
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Jakub Šťastný aka Botanicus
1
+ Copyright (c) 2009 – 2010 Jakub Šťastný aka Botanicus
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.textile CHANGED
@@ -1,10 +1,58 @@
1
1
  h1. About
2
2
 
3
+ This Rails plugin provides *template inheritance* from "Rango":http://github.com/botanicus/rango for Rails, so you can just install it and enjoy advantages of template inheritance without any framework switching.
4
+
5
+ Please note that this plugin works just with *Ruby 1.9.1 and higher*!
6
+
7
+ See an "example application":http://github.com/botanicus/rango-in-rails
8
+
3
9
  h2. Template Inheritance
4
10
 
11
+ "Template inheritance":http://wiki.github.com/botanicus/rango/template-inheritance is incredibly simple, powerful and flexible way how to handle layout/template. You usually needs more levels of layouting and you can do it very easily with template inheritance. You can have i. e. @app/views/admin/posts/show.html.haml@ with post-specific stuff, then @app/views/admin/base.html.haml@ with administration-specific layout and then @app/views/base.html.haml@ with the most generic layout.
12
+
13
+ See also "explanation at DjangoProject.com":http://docs.djangoproject.com/en/dev/topics/templates/#template-inheritance
14
+
5
15
  h2. Rango
6
16
 
17
+ "Rango":http://github.com/botanicus/rango is a light-weight web framework suitable for both smaller web services and bigger sites. It's builded on top of Rack and it has very flexible and modular architecture. So modular that we can even use it in Rails as a drop-in replacement for Rails rendering layer.
18
+
19
+ - "Rango Wiki":http://wiki.github.com/botanicus/rango
20
+ - "Rango Introduction from Ruby Manor 2009":http://www.slideshare.net/botanicus/rango
21
+
22
+ h2. Template Adapters
23
+
24
+ Thanks to "Tilt":http://github.com/rtomayko/tilt you can use Erubis or Haml, just by using the proper extension. Tilt itself supports much more, however Rango currently support just these two engines. Some engines won't be supported just because they don't support Ruby code in templates (Mustache and Liquid) etc.
25
+
7
26
  h1. Usage
8
27
 
9
- # As a plugin: @./script/plugin install git://github.com/botanicus/rails-template-inheritance.git@
10
- # As a gem:
28
+ h2. As a Plugin
29
+
30
+ @./script/plugin install git://github.com/botanicus/rails-template-inheritance.git@
31
+
32
+ h2. As a Gem
33
+
34
+ Add these lines into your @config/environment.rb@:
35
+
36
+ <pre>
37
+ config.gem "tilt"
38
+ config.gem "rango", lib: nil
39
+ config.gem "rails-template-inheritance", lib: nil
40
+ </pre>
41
+
42
+ Now run following tasks:
43
+
44
+ <pre>
45
+ rake gems:install
46
+ rake gems:unpack
47
+ </pre>
48
+
49
+ h2. Via "bundler":http://github.com/wycats/bundler
50
+
51
+ This is definitely the best solution since plugins can't handle dependencies and Rails 2 bundling tasks are just general pain in the ass.
52
+
53
+ Just put @gem "rails-template-inheritance"@ to your @Gemfile@ and run @gem bundle@ (you have to have bundler installed). Then you have to setup your @config/environment.rb@:
54
+
55
+ <pre>
56
+ require_relative "../vendor/gems/environment"
57
+ Bundler.require_env(Rails.env)
58
+ </pre>
data/TODO.txt ADDED
@@ -0,0 +1,2 @@
1
+ - add examples/blog or something with more sophisticated setup, so users can see the real benefit of template inheritance
2
+ - move examples to examples/basic and add some specs
@@ -6,13 +6,14 @@ end
6
6
 
7
7
  require "tilt"
8
8
  require "rango/mixins/render"
9
+ require "action_view/helpers"
9
10
 
10
11
  # Rango setup
11
12
  Tilt.register "erb", Tilt::ErubisTemplate # extension "erb" => erubis template
12
13
  Rango.logger = Rails.logger
13
14
 
14
15
  # Rango::Template has just getter, because then it holds just one object,
15
- # so if you create a reference, it will just work.
16
+ # so if you create a reference to, it will just work.
16
17
  # You can use Rango::Template.template.paths.clear.unshift(path)
17
18
  module Rango
18
19
  class Template
@@ -28,7 +29,22 @@ module ActionController
28
29
  Rango::Template.template_paths = @template.view_paths
29
30
  path = template_path.respond_to?(:path_without_format_and_extension) ? template_path.path_without_format_and_extension : template_path
30
31
  logger.info("Rendering #{path}" + (status ? " (#{status})" : '')) if logger
31
- render_for_text Rango::RenderMixin.render(template_path.template_path, self, locals), status
32
+ render_for_text Rango::RenderMixin.render(template_path.template_path, self.scope, self.locals), status
33
+ end
34
+
35
+ def locals
36
+ @locals ||= {request: request}
37
+ end
38
+
39
+ def scope
40
+ self.dup.tap do |scope|
41
+ scope.extend(self.class.master_helper_module)
42
+ ActionView::Helpers.constants.grep(/Helper$/).each do |name|
43
+ helper = ActionView::Helpers.const_get(name)
44
+ scope.extend(helper)
45
+ scope.instance_variable_set(:@controller, self)
46
+ end
47
+ end
32
48
  end
33
49
  end
34
50
  end
@@ -1,19 +1,22 @@
1
1
  #!/usr/bin/env gem build
2
2
  # encoding: utf-8
3
3
 
4
+ require "base64"
5
+
4
6
  Gem::Specification.new do |s|
5
7
  s.name = "rails-template-inheritance"
6
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
7
9
  s.authors = ["Jakub Šťastný aka Botanicus"]
8
10
  s.homepage = "http://github.com/botanicus/rails-template-inheritance"
9
11
  s.summary = "Template inheritance provided by Rango in Rails!"
10
12
  s.description = "" # TODO: long description
11
13
  s.cert_chain = nil
12
- s.email = ["knava.bestvinensis", "gmail.com"].join("@")
14
+ s.email = Base64.decode64("c3Rhc3RueUAxMDFpZGVhcy5jeg==\n")
13
15
  s.has_rdoc = true
14
16
 
15
17
  # files
16
- s.files = Dir.glob("{lib,spec}/**/*") + Dir["*"]
18
+ s.files = `git ls-files`.split("\n")
19
+
17
20
  s.require_paths = ["lib"]
18
21
 
19
22
  # Ruby version
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-template-inheritance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Jakub \xC5\xA0\xC5\xA5astn\xC3\xBD aka Botanicus"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
- date: 2009-12-14 00:00:00 +00:00
11
+ date: 2010-01-16 00:00:00 +00:00
12
12
  default_executable:
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: "0"
33
33
  version:
34
34
  description: ""
35
- email: knava.bestvinensis@gmail.com
35
+ email: stastny@101ideas.cz
36
36
  executables: []
37
37
 
38
38
  extensions: []
@@ -40,11 +40,14 @@ extensions: []
40
40
  extra_rdoc_files: []
41
41
 
42
42
  files:
43
- - lib/rails-template-inheritance.rb
44
- - init.rb
43
+ - .gitignore
44
+ - .gitmodules
45
45
  - LICENSE
46
- - rails-template-inheritance.gemspec
47
46
  - README.textile
47
+ - TODO.txt
48
+ - init.rb
49
+ - lib/rails-template-inheritance.rb
50
+ - rails-template-inheritance.gemspec
48
51
  has_rdoc: true
49
52
  homepage: http://github.com/botanicus/rails-template-inheritance
50
53
  licenses: []