-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2e2f4f1
Showing
8 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pkg/* | ||
*.gem | ||
.bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in walrus.gemspec | ||
gemspec | ||
gem 'rails', '>=3.0.0' | ||
gem 'mustache' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'walrus/handler' | ||
require 'walrus/view' | ||
|
||
ActionView::Template.register_template_handler(:mustache, Walrus::Handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Walrus | ||
class Handler < ActionView::Template::Handler | ||
include ActionView::Template::Handlers::Compilable | ||
|
||
self.default_format = :mustache | ||
|
||
def compile(template) | ||
view_path = "#{template.virtual_path}_view" | ||
abs_view_path = Rails.root.join('app/views', view_path) | ||
if File.exists? "#{abs_view_path}.rb" | ||
require abs_view_path | ||
view_class = view_path.sub('/_','/').classify.constantize | ||
Rails.logger.debug(view_class) | ||
else | ||
view_class = Walrus::View | ||
end | ||
"#{view_class}.new(self, '#{template.source.gsub(/'/, "\\\\'")}').render.html_safe" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module Walrus | ||
VERSION = "0.0.1" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module Walrus | ||
class View < Mustache | ||
|
||
def initialize(view_context, template_source) | ||
@view_context = view_context | ||
self.template = template_source | ||
assign_variables! | ||
end | ||
|
||
def respond_to?(method_sym, include_private = false) | ||
if view_context.respond_to?(method_sym) | ||
true | ||
else | ||
super | ||
end | ||
end | ||
|
||
def method_missing(method_name, *args, &block) | ||
instance_var = instance_variable_get("@#{method_name}") | ||
if defined?(instance_var) && args.empty? | ||
instance_var | ||
else | ||
view_context.send(method_name,*args, &block) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :view_context | ||
|
||
def assign_variables! | ||
variables = view_context.instance_variable_names.select{|name| name =~ /^@[^_]/} | ||
variables.each do |name| | ||
instance_var = view_context.instance_variable_get(name) | ||
instance_variable_set(name, instance_var) | ||
self[name.tr('@','').to_sym] = instance_var | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "walrus/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "walrus" | ||
s.version = Walrus::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ["Oliver Nightingale", "Mark Evans"] | ||
s.email = ["oliver.nightingale1@gmail.com"] | ||
s.homepage = "http://rubygems.org/gems/walrus" | ||
s.summary = %q{mustaches} | ||
s.description = %q{mustaches are cool} | ||
|
||
s.rubyforge_project = "walrus" | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
end |