Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

PogoScript support #176

Open
wants to merge 1 commit into from

2 participants

@joshski

Support for the PogoScript language

@judofyr
Collaborator

Thanks for the contribution! I'm going to have a look at this after we've solved encodings (#175).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 3, 2015
  1. @joshski

    pogoscript support

    joshski authored
This page is out of date. Refresh to see the latest.
View
2  Gemfile
@@ -21,6 +21,7 @@ group :engines do
gem 'markaby'
gem 'maruku'
gem 'nokogiri' if RUBY_VERSION > '1.9.2'
+ gem 'pogo-script'
gem 'radius'
gem 'sass'
gem 'rdoc', (ENV['RDOC_VERSION'] || '> 0')
@@ -43,4 +44,3 @@ end
platform :rbx do
gem 'rubysl'
end
-
View
1  README.md
@@ -47,6 +47,7 @@ Support for these template engines is included with the package:
| Markaby | .mab | markaby |
| Nokogiri | .nokogiri | nokogiri |
| CoffeeScript | .coffee | coffee-script (+ javascript) |
+| PogoScript | .pogo | pogo-script (+ javascript) |
| Creole (Wiki markup) | .wiki, .creole | creole |
| WikiCloth (Wiki markup) | .wiki, .mediawiki, .mw | wikicloth |
| Yajl | .yajl | yajl-ruby |
View
2  docs/TEMPLATES.md
@@ -34,6 +34,7 @@ Tilt also includes support for CSS processors like [LessCSS][lesscss] and
* [Textile](#redcloth) - `Tilt::RedClothTemplate`
* Creole - `Tilt::CreoleTemplate`
* [RDoc](#rdoc) - `Tilt::RDocTemplate`
+ * PogoScript - `Tilt::PogoScriptTemplate`
Tilt has extensive support for Markdown, backed by one of four different
implementations (depending on which are available on your system):
@@ -509,6 +510,7 @@ using this template engine within a threaded environment.
[lesscss]: http://lesscss.org/ "Less CSS"
[sass]: http://sass-lang.com/ "Sass"
[coffee-script]: http://jashkenas.github.com/coffee-script/ "Coffee Script"
+[pogo-script]: http://pogoscript.org/ "PogoScript"
[erubis]: http://www.kuwata-lab.com/erubis/ "Erubis"
[haml]: http://haml.info/ "Haml"
[liquid]: http://www.liquidmarkup.org/ "Liquid"
View
1  lib/tilt.rb
@@ -115,6 +115,7 @@ def clear
register_lazy :BuilderTemplate, 'tilt/builder', 'builder'
register_lazy :CSVTemplate, 'tilt/csv', 'rcsv'
register_lazy :CoffeeScriptTemplate, 'tilt/coffee', 'coffee'
+ register_lazy :PogoScriptTemplate, 'tilt/pogo', 'pogo'
register_lazy :CreoleTemplate, 'tilt/creole', 'wiki', 'creole'
register_lazy :EtanniTemplate, 'tilt/etanni', 'etn', 'etanni'
register_lazy :HamlTemplate, 'tilt/haml', 'haml'
View
44 lib/tilt/pogo.rb
@@ -0,0 +1,44 @@
+require 'tilt/template'
+require 'pogo_script'
+
+module Tilt
+ # PogoScript template implementation. See:
+ # http://pogoscript.org/
+ #
+ # PogoScript templates do not support object scopes, locals, or yield.
+ class PogoScriptTemplate < Template
+ self.default_mime_type = 'application/javascript'
+
+ @@default_bare = false
+
+ def self.default_bare
+ @@default_bare
+ end
+
+ def self.default_bare=(value)
+ @@default_bare = value
+ end
+
+ def self.engine_initialized?
+ defined? ::PogoScript
+ end
+
+ def initialize_engine
+ require_template_library 'pogo_script'
+ end
+
+ def prepare
+ if !options.key?(:bare) and !options.key?(:no_wrap)
+ options[:bare] = self.class.default_bare
+ end
+ end
+
+ def evaluate(scope, locals, &block)
+ @output ||= PogoScript.compile(data, options)
+ end
+
+ def allows_script?
+ false
+ end
+ end
+end
View
88 test/tilt_pogoscripttemplate_test.rb
@@ -0,0 +1,88 @@
+require 'test_helper'
+require 'tilt'
+
+begin
+ require 'tilt/pogo'
+
+ class PogoScriptTemplateTest < Minitest::Test
+
+ test "is registered for '.pogo' files" do
+ assert_equal Tilt::PogoScriptTemplate, Tilt['test.pogo']
+ end
+
+ test "bare is disabled by default" do
+ assert_equal false, Tilt::PogoScriptTemplate.default_bare
+ end
+
+ test "compiles and evaluates the template on #render" do
+ template = Tilt::PogoScriptTemplate.new { |t| "puts 'Hello, World!'\n" }
+ assert_match "puts('Hello, World!');", template.render
+ end
+
+ test "can be rendered more than once" do
+ template = Tilt::PogoScriptTemplate.new { |t| "puts 'Hello, World!'\n" }
+ 3.times { assert_match "puts('Hello, World!');", template.render }
+ end
+
+ test "disabling pogo-script wrapper" do
+ str = %|name = "Josh"\nputs "Hello, #(name)"|
+
+ template = Tilt::PogoScriptTemplate.new { str }
+ assert_match "(function(){", template.render
+ assert_match "puts(('Hello, '+name));", template.render
+
+ template = Tilt::PogoScriptTemplate.new(:bare => true) { str }
+ refute_match "(function(){", template.render
+ assert_equal "var name;name='Josh';puts(('Hello, '+name));", template.render
+ end
+
+ context "wrapper globally enabled" do
+ setup do
+ @bare = Tilt::PogoScriptTemplate.default_bare
+ Tilt::PogoScriptTemplate.default_bare = false
+ end
+
+ teardown do
+ Tilt::PogoScriptTemplate.default_bare = @bare
+ end
+
+ test "no options" do
+ template = Tilt::PogoScriptTemplate.new { |t| %|name = "Josh"\nputs "Hello, #(name)"| }
+ assert_match "puts(('Hello, '+name));", template.render
+ assert_match "(function(){", template.render
+ end
+
+ test "overridden by :bare" do
+ template = Tilt::PogoScriptTemplate.new(:bare => true) { |t| %|name = "Josh"\nputs "Hello, #(name)"| }
+ assert_match "puts(('Hello, '+name));", template.render
+ refute_match "(function(){", template.render
+ end
+ end
+
+ context "wrapper globally disabled" do
+ setup do
+ @bare = Tilt::PogoScriptTemplate.default_bare
+ Tilt::PogoScriptTemplate.default_bare = true
+ end
+
+ teardown do
+ Tilt::PogoScriptTemplate.default_bare = @bare
+ end
+
+ test "no options" do
+ template = Tilt::PogoScriptTemplate.new { |t| %|name = "Josh"\nputs "Hello, #(name)"| }
+ assert_match "puts(('Hello, '+name));", template.render
+ refute_match "(function(){", template.render
+ end
+
+ test "overridden by :bare" do
+ template = Tilt::PogoScriptTemplate.new(:bare => false) { |t| %|name = "Josh"\nputs "Hello, #(name)"| }
+ assert_match "puts(('Hello, '+name));", template.render
+ assert_match "(function(){", template.render
+ end
+ end
+ end
+
+rescue LoadError => boom
+ warn "Tilt::PogoScriptTemplate (disabled)"
+end
View
2  tilt.gemspec
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
lib/tilt/maruku.rb
lib/tilt/nokogiri.rb
lib/tilt/plain.rb
+ lib/tilt/pogo.rb
lib/tilt/radius.rb
lib/tilt/rdiscount.rb
lib/tilt/rdoc.rb
@@ -82,6 +83,7 @@ Gem::Specification.new do |s|
test/tilt_marukutemplate_test.rb
test/tilt_metadata_test.rb
test/tilt_nokogiritemplate_test.rb
+ test/tilt_pogoscripttemplate_test.rb
test/tilt_radiustemplate_test.rb
test/tilt_rdiscounttemplate_test.rb
test/tilt_rdoctemplate_test.rb
Something went wrong with that request. Please try again.