pax_global_header00006660000000000000000000000064142665733770014536gustar00rootroot0000000000000052 comment=d1999c72408abad8ff30b754fb5a8f3a682c2aac tilt-2.0.11/000077500000000000000000000000001426657337700125735ustar00rootroot00000000000000tilt-2.0.11/.autotest000066400000000000000000000005301426657337700144420ustar00rootroot00000000000000require 'rubygems' require 'bacon' require 'autotest/bacon' class Autotest::Bacon < Autotest undef make_test_cmd def make_test_cmd(files_to_test) args = files_to_test.keys.flatten.join(' ') args = '-a' if args.empty? # TODO : make regex to pass to -n using values "#{ruby} -S bacon -I#{libs} -o TestUnit #{args}" end end tilt-2.0.11/.github/000077500000000000000000000000001426657337700141335ustar00rootroot00000000000000tilt-2.0.11/.github/workflows/000077500000000000000000000000001426657337700161705ustar00rootroot00000000000000tilt-2.0.11/.github/workflows/test.yml000066400000000000000000000021301426657337700176660ustar00rootroot00000000000000name: "Test suite" on: [push] jobs: test: runs-on: ubuntu-latest strategy: fail-fast: false matrix: ruby: # We test on all stable versions of Ruby - "2.7" - "3.0" - "3.1" - "jruby" # … but only the primary templates bundle_without: ["secondary:development"] title: ["primary templates"] # In addition we test for the secondary templates on the latest version of Ruby include: - ruby: "3.1" bundle_without: "primary:development" title: "secondary templates" env: BUNDLE_WITHOUT: ${{ matrix.bundle_without }} name: Ruby ${{ matrix.ruby }} (${{ matrix.title }}) steps: - uses: actions/checkout@v2 - name: Install dependencies # WikiCloth needs IDN # Pandoc needs Pandoc run: sudo apt-get install -y libidn11-dev pandoc - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - name: Run test suite run: bundle exec rake tilt-2.0.11/.gitignore000066400000000000000000000001121426657337700145550ustar00rootroot00000000000000/dist *.swp /Gemfile.lock /vendor /.bundle /.yardoc /doc .sass-cache /man tilt-2.0.11/.travis.yml000066400000000000000000000016371426657337700147130ustar00rootroot00000000000000sudo: false addons: apt: sources: - kalakris-cmake packages: - cmake - pandoc language: ruby rvm: - 2.1.10 - 2.2.7 - 2.3.4 - 2.4.1 - 2.5.3 - ruby-head - jruby-9.1.5.0 - truffleruby-head env: - BUNDLE_WITHOUT=secondary:development SASS_IMPLEMENTATION=sassc FORCE_SASS=1 - BUNDLE_WITHOUT=primary:development install: - curl -L https://github.com/gliderlabs/sigil/releases/download/v0.4.0/sigil_0.4.0_Linux_x86_64.tgz | tar -zxC $TRAVIS_BUILD_DIR/bin/ script: - bundle install - export PATH=$TRAVIS_BUILD_DIR/bin:$PATH; bundle exec rake matrix: allow_failures: - env: BUNDLE_WITHOUT=primary:development - rvm: ruby-head fast_finish: true include: - rvm: 2.4.1 env: BUNDLE_WITHOUT=secondary:development SASS_IMPLEMENTATION=sass FORCE_SASS=1 - rvm: 2.7.6 env: BUNDLE_WITHOUT=secondary:development SASS_IMPLEMENTATION=sass-embedded FORCE_SASS=1 tilt-2.0.11/CHANGELOG.md000066400000000000000000000113371426657337700144110ustar00rootroot00000000000000## master ## 2.0.11 (2022-07-22) * Fix #extensions\_for for RedcarpetTemplate (judofyr) * Support the new sass-embedded gem (#367, ntkme) * Add Tilt::EmacsOrg support (#366, hacktivista) * Improve rendering of BasicObject instances (#348, jeremyevans) * Fix Ruby 3.0 compatibility (#360, voxik) ## 2.0.10 (2019-09-23) * Remove test files from bundled gem (#339, greysteil) * Fix warning when using yield in templates on ruby 2.7 (#343, jeremyevans) ## 2.0.9 (2018-11-28) * Use new ERB API in Ruby 2.6 (#329, koic) * Support the new sassc gem (#336, jdickey, judofyr) ## 2.0.8 (2017-07-24) * Register .tsx for TypeScript (#315, backus) * Use Haml 5's new API (#312, k0kubun) * Use correct parser options for CommonMarker (#320, rewritten) * Suppress warnings when no locals are used (#304, amatsuda) * Haml: Accept `outvar` (#317, k0kubun) ## 2.0.7 (2017-03-19) * Do not modify BasicObject during template compilation on ruby 2.0+ (#309, jeremyevans) ## 2.0.6 (2017-01-26) * Add support for LiveScript (#286, @Announcement Jacob Francis Powers) * Add support for Sigil (#302, winebarrel) * Add support for Erubi (#308, jeremyevans) * Add support for options in Liquid (#298, #299, laCour) * Always sort locals by strings (#307, jeremyevans) * Fix test warnings (#305, amatsuda) * Fix indentation (#293, yui-knk) * Use SVG badges in README (#294, vasinov) * Fix typo and trailing space (#295, #296, karloescota) ## 2.0.5 (2016-06-02) * Add support for reST using Pandoc (#284, mfenner) * Make lazy loading thread-safe; remove warning (judofyr) ## 2.0.4 (2016-05-16) * Fix regression in BuilderTemplate (#283, judofyr) ## 2.0.3 (2016-05-12) * Add Pandoc support (#276, jmuheim) * Add CommonMark support (#282, raphink) * Add TypeScript support (#278, nghitran) * Work with frozen string literal (#274, jeremyevans) * Add MIME type for Babel (#273, SaitoWu) ## 2.0.2 (2016-01-06) * Pass options to Redcarpet (#250, hughbien) * Haml: Improve error message on frozen self (judofyr) * Add basic support for Babel (judofyr) * Add support for .litcoffee (#243, judofyr, mr-vinn) * Document Tilt::Cache (#266, tommay) * Sort local keys for better caching (#257, jeremyevans) * Add more CSV options (#256, Juanmcuello) * Add Prawn template (kematzy) * Improve cache-miss performance in Tilt::Cache (#251, tommay) * Add man page (#241, josephholsten) * Support YAML/JSON data in bin/tilt (#241, josephholsten) ## 2.0.1 (2014-03-21) * Fix Tilt::Mapping bug in Ruby 2.1.0 (9589652c569760298f2647f7a0f9ed4f85129f20) * Fix `tilt --list` (#223, Achrome) * Fix circular require (#221, amarshall) ## 2.0.0 (2013-11-30) * Support Pathname in Template#new (#219, kabturek) * Add Mapping#templates_for (judofyr) * Support old-style #register (judofyr) * Add Handlebars as external template engine (#204, judofyr, jimothyGator) * Add org-ruby as external template engine (#207, judofyr, minad) * Documentation typo (#208, elgalu) ## 2.0.0.beta1 (2013-07-16) * Documentation typo (#202, chip) * Use YARD for documentation (#189, judofyr) * Add Slim as an external template engine (judofyr) * Add Tilt.templates_for (#121, judofyr) * Add Tilt.current_template (#151, judofyr) * Avoid loading all files in tilt.rb (#160, #187, judofyr) * Implement lazily required templates classes (#178, #187, judofyr) * Move #allows_script and default_mime_type to metadata (#187, judofyr) * Introduce Tilt::Mapping (#187, judofyr) * Make template compilation thread-safe (#191, judofyr) ## 1.4.1 (2013-05-08) * Support Arrays in pre/postambles (#193, jbwiv) ## 1.4.0 (2013-05-01) * Better encoding support ## 1.3.7 (2013-04-09) * Erubis: Check for the correct constant (#183, mattwildig) * Don't fail when BasicObject is defined in 1.8 (#182, technobrat, judofyr) ## 1.3.6 (2013-03-17) * Accept Hash that implements #path as options (#180, lawso017) * Changed extension for CsvTemplate from '.csv' to '.rcsv' (#177, alexgb) ## 1.3.5 (2013-03-06) * Fixed extension for PlainTemplate (judofyr) * Improved local variables regexp (#174, razorinc) * Added CHANGELOG.md ## 1.3.4 (2013-02-28) * Support RDoc 4.0 (#168, judofyr) * Add mention of Org-Mode support (#165, aslakknutsen) * Add AsciiDoctorTemplate (#163, #164, aslakknutsen) * Add PlainTextTemplate (nathanaeljones) * Restrict locals to valid variable names (#158, thinkerbot) * ERB: Improve trim mode support (#156, ssimeonov) * Add CSVTemplate (#153, alexgb) * Remove special case for 1.9.1 (#147, guilleiguaran) * Add allows\_script? method to Template (#143, bhollis) * Default to using Redcarpet2 (#139, DAddYE) * Allow File/Tempfile as filenames (#134, jamesotron) * Add EtanniTemplate (#131, manveru) * Support RDoc 3.10 (#112, timfel) * Always compile templates; remove old source evaluator (rtomayko) * Less: Options are now being passed to the parser (#106, cowboyd) tilt-2.0.11/COPYING000066400000000000000000000020531426657337700136260ustar00rootroot00000000000000Copyright (c) 2010-2016 Ryan Tomayko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tilt-2.0.11/Gemfile000066400000000000000000000026211426657337700140670ustar00rootroot00000000000000source 'https://rubygems.org' gemspec gem 'rake' gem 'minitest', '~> 5.0' group :development do gem 'yard', '~> 0.9.0' gem 'ronn', '~> 0.7.3' end group :primary do gem 'builder' gem 'haml', '>= 4' gem 'erubis' gem 'markaby' case ENV['SASS_IMPLEMENTATION'] when 'sass' gem 'sass' when 'sassc' gem 'sassc' else gem 'sass-embedded' end gem 'less' gem 'coffee-script' gem 'livescript' gem 'babel-transpiler' gem 'typescript-node' end platform :mri do gem 'duktape', '~> 1.3.0.6' end group :secondary do gem 'creole' gem 'kramdown' gem 'rdoc' gem 'radius' gem 'asciidoctor', '>= 0.1.0' gem 'liquid' gem 'maruku' gem 'pandoc-ruby' if RUBY_VERSION > '1.9.3' gem 'prawn', '>= 2.0.0' gem 'pdf-reader', '~> 1.3.3' end gem 'nokogiri' # Both rdiscount and bluecloth embeds Discount and loading # both at the same time causes strange issues. discount_gem = ENV["DISCOUNT_GEM"] || "rdiscount" raise "DISCOUNT_GEM must be set to 'rdiscount' or 'bluecloth'" if !%w[rdiscount bluecloth].include?(discount_gem) platform :ruby do gem 'wikicloth' gem 'rinku' # dependency for wikicloth for handling links gem 'yajl-ruby' gem 'redcarpet' gem 'rdiscount', '>= 2.1.6' if discount_gem == "rdiscount" gem 'RedCloth' gem 'commonmarker' end platform :mri do gem 'bluecloth' if discount_gem == "bluecloth" end end tilt-2.0.11/HACKING000066400000000000000000000004561426657337700135670ustar00rootroot00000000000000Clone: git clone git://github.com/rtomayko/tilt.git cd tilt Install needed packages under ./vendor and run tests (requires bundler): rake Run tests under your current gem environment. Do not install anything: rake test Only install needed packages under ./vendor: rake setup tilt-2.0.11/README.md000066400000000000000000000276721426657337700140700ustar00rootroot00000000000000Tilt [![Build Status](https://secure.travis-ci.org/rtomayko/tilt.svg)](http://travis-ci.org/rtomayko/tilt) [![Inline docs](http://inch-ci.org/github/rtomayko/tilt.svg)](http://inch-ci.org/github/rtomayko/tilt) [![Security](https://hakiri.io/github/rtomayko/tilt/master.svg)](https://hakiri.io/github/rtomayko/tilt/master) ==== **NOTE** The following file documents the current release of Tilt (2.0). See https://github.com/rtomayko/tilt/tree/tilt-1 for documentation for Tilt 1.4. Tilt is a thin interface over a bunch of different Ruby template engines in an attempt to make their usage as generic as possible. This is useful for web frameworks, static site generators, and other systems that support multiple template engines but don't want to code for each of them individually. The following features are supported for all template engines (assuming the feature is relevant to the engine): * Custom template evaluation scopes / bindings * Ability to pass locals to template evaluation * Support for passing a block to template evaluation for "yield" * Backtraces with correct filenames and line numbers * Template file caching and reloading * Fast, method-based template source compilation The primary goal is to get all of the things listed above right for all template engines included in the distribution. Support for these template engines is included with the package: | Engine | File Extensions | Required Libraries | Maintainer | | ----------------------- | ---------------------- | ------------------------------------------ | ----------- | | Asciidoctor | .ad, .adoc, .asciidoc | asciidoctor (>= 0.1.0) | Community | | ERB | .erb, .rhtml | none (included ruby stdlib) | Tilt team | | InterpolatedString | .str | none (included ruby core) | Tilt team | | Erubi | .erb, .rhtml, .erubi | erubi | Community | | Erubis | .erb, .rhtml, .erubis | erubis | Tilt team | | Haml | .haml | haml | Tilt team | | Sass | .sass | sass-embedded (>= 1.0) or sassc (>=2.0) | Tilt team | | Scss | .scss | sass-embedded (>= 1.0) or sassc (>=2.0) | Tilt team | | Less CSS | .less | less | Tilt team | | Builder | .builder | builder | Tilt team | | Liquid | .liquid | liquid | Community | | RDiscount | .markdown, .mkd, .md | rdiscount | Community | | Redcarpet | .markdown, .mkd, .md | redcarpet | Community | | BlueCloth | .markdown, .mkd, .md | bluecloth | Community | | Kramdown | .markdown, .mkd, .md | kramdown | Community | | Pandoc | .markdown, .mkd, .md | pandoc | Community | | reStructuredText | .rst | pandoc | Community | | Maruku | .markdown, .mkd, .md | maruku | Community | | CommonMarker | .markdown, .mkd, .md | commonmarker | Community | | RedCloth | .textile | redcloth | Community | | RDoc | .rdoc | rdoc | Tilt team | | Radius | .radius | radius | Community | | Markaby | .mab | markaby | Tilt team | | Nokogiri | .nokogiri | nokogiri | Community | | CoffeeScript | .coffee | coffee-script (+ javascript) | Tilt team | | CoffeeScript (literate) | .litcoffee | coffee-script (>= 1.5.0) (+ javascript) | Tilt team | | LiveScript | .ls | livescript (+ javascript) | Tilt team | | TypeScript | .ts | typescript (+ javascript) | Tilt team | | Creole (Wiki markup) | .wiki, .creole | creole | Community | | WikiCloth (Wiki markup) | .wiki, .mediawiki, .mw | wikicloth | Community | | Yajl | .yajl | yajl-ruby | Community | | CSV | .rcsv | none (Ruby >= 1.9), fastercsv (Ruby < 1.9) | Tilt team | | Prawn | .prawn | prawn (>= 2.0.0) | Community | | Babel | .es6, .babel, .jsx | babel-transpiler | Tilt team | | Opal | .rb | opal | Community | | Sigil | .sigil | sigil | Community | Every supported template engine has a *maintainer*. Note that this is the maintainer of the Tilt integration, not the maintainer of the template engine itself. The maintainer is responsible for providing an adequate integration and keeping backwards compatibility across Tilt version. Some integrations are maintained by the *community*, which is handled in the following way: - The Tilt team will liberally accept pull requests against the template integration. It's up to the community as a whole to make sure the integration stays consistent and backwards compatible over time. - Test failures in community-maintained integrations will not be prioritized by the Tilt team and a new version of Tilt might be released even though these tests are failing. - Anyone can become a maintainer for a template engine integration they care about. Just open an issue and we'll figure it out. These template engines ship with their own Tilt integration: | Engine | File Extensions | Required Libraries | | ------------------- | ---------------- | ------------------- | | Slim | .slim | slim (>= 0.7) | | Embedded JavaScript | | sprockets | | Embedded CoffeeScript | | sprockets | | JST | | sprockets | | Org-mode | .org | org-ruby (>= 0.6.2) | | Emacs Org | .org | tilt-emacs_org | | Handlebars | .hbs, handlebars | tilt-handlebars | | Jbuilder | .jbuilder | tilt-jbuilder | See [TEMPLATES.md][t] for detailed information on template engine options and supported features. [t]: http://github.com/rtomayko/tilt/blob/master/docs/TEMPLATES.md "Tilt Template Engine Documentation" Basic Usage ----------- Instant gratification: ~~~ruby require 'erb' require 'tilt' template = Tilt.new('templates/foo.erb') => # output = template.render => "Hello world!" ~~~ It's recommended that calling programs explicitly require template engine libraries (like 'erb' above) at load time. Tilt attempts to lazy require the template engine library the first time a template is created but this is prone to error in threaded environments. The {Tilt} module contains generic implementation classes for all supported template engines. Each template class adheres to the same interface for creation and rendering. In the instant gratification example, we let Tilt determine the template implementation class based on the filename, but {Tilt::Template} implementations can also be used directly: ~~~ruby require 'tilt/haml' template = Tilt::HamlTemplate.new('templates/foo.haml') output = template.render ~~~ The `render` method takes an optional evaluation scope and locals hash arguments. Here, the template is evaluated within the context of the `Person` object with locals `x` and `y`: ~~~ruby require 'tilt/erb' template = Tilt::ERBTemplate.new('templates/foo.erb') joe = Person.find('joe') output = template.render(joe, :x => 35, :y => 42) ~~~ If no scope is provided, the template is evaluated within the context of an object created with `Object.new`. A single `Template` instance's `render` method may be called multiple times with different scope and locals arguments. Continuing the previous example, we render the same compiled template but this time in jane's scope: ~~~ruby jane = Person.find('jane') output = template.render(jane, :x => 22, :y => nil) ~~~ Blocks can be passed to `render` for templates that support running arbitrary ruby code (usually with some form of `yield`). For instance, assuming the following in `foo.erb`: ~~~ruby Hey <%= yield %>! ~~~ The block passed to `render` is called on `yield`: ~~~ruby template = Tilt::ERBTemplate.new('foo.erb') template.render { 'Joe' } # => "Hey Joe!" ~~~ Template Mappings ----------------- The {Tilt::Mapping} class includes methods for associating template implementation classes with filename patterns and for locating/instantiating template classes based on those associations. The {Tilt} module has a global instance of `Mapping` that is populated with the table of template engines above. The {Tilt.register} method associates a filename pattern with a specific template implementation. To use ERB for files ending in a `.bar` extension: ~~~ruby >> Tilt.register Tilt::ERBTemplate, 'bar' >> Tilt.new('views/foo.bar') => # ~~~ Retrieving the template class for a file or file extension: ~~~ruby >> Tilt['foo.bar'] => Tilt::ERBTemplate >> Tilt['haml'] => Tilt::HamlTemplate ~~~ Retrieving a list of template classes for a file: ~~~ruby >> Tilt.templates_for('foo.bar') => [Tilt::ERBTemplate] >> Tilt.templates_for('foo.haml.bar') => [Tilt::ERBTemplate, Tilt::HamlTemplate] ~~~ The template class is determined by searching for a series of decreasingly specific name patterns. When creating a new template with `Tilt.new('views/foo.html.erb')`, we check for the following template mappings: 1. `views/foo.html.erb` 2. `foo.html.erb` 3. `html.erb` 4. `erb` Encodings --------- Tilt needs to know the encoding of the template in order to work properly: Tilt will use `Encoding.default_external` as the encoding when reading external files. If you're mostly working with one encoding (e.g. UTF-8) we *highly* recommend setting this option. When providing a custom reader block (`Tilt.new { custom_string }`) you'll have ensure the string is properly encoded yourself. Most of the template engines in Tilt also allows you to override the encoding using the `:default_encoding`-option: ~~~ruby tmpl = Tilt.new('hello.erb', :default_encoding => 'Big5') ~~~ Ultimately it's up to the template engine how to handle the encoding: It might respect `:default_encoding`, it might always assume it's UTF-8 (like CoffeeScript), or it can do its own encoding detection. Template Compilation -------------------- Tilt compiles generated Ruby source code produced by template engines and reuses it on subsequent template invocations. Benchmarks show this yields a 5x-10x performance increase over evaluating the Ruby source on each invocation. Template compilation is currently supported for these template engines: StringTemplate, ERB, Erubis, Haml, Nokogiri, Builder and Yajl. LICENSE ------- Tilt is Copyright (c) 2010 [Ryan Tomayko](http://tomayko.com/about) and distributed under the MIT license. See the `COPYING` file for more info. tilt-2.0.11/Rakefile000066400000000000000000000055631426657337700142510ustar00rootroot00000000000000require 'bundler' Bundler.setup require 'rake/testtask' task :default => [:test] # SPECS ===================================================================== desc 'Run tests (default)' Rake::TestTask.new(:test) do |t| t.test_files = FileList['test/*_test.rb'] t.ruby_opts = ['-Itest'] t.ruby_opts << '-rrubygems' if defined? Gem t.warning = false end # DOCUMENTATION ============================================================= begin require 'yard' YARD::Rake::YardocTask.new do |t| t.files = [ 'lib/tilt.rb', 'lib/tilt/mapping.rb', 'lib/tilt/template.rb', '-', '*.md', 'docs/*.md', ] t.options << '--no-private' << '--protected' << '-m' << 'markdown' << '--asset' << 'docs/common.css:css/common.css' end rescue LoadError end task :man do require 'ronn' ENV['RONN_MANUAL'] = "Tilt Manual" ENV['RONN_ORGANIZATION'] = "Tilt #{SPEC.version}" sh "ronn -w -s toc -r5 --markdown man/*.ronn" end # PACKAGING ================================================================= begin require 'rubygems' rescue LoadError end if defined?(Gem) SPEC = eval(File.read('tilt.gemspec')) def package(ext='') "pkg/tilt-#{SPEC.version}" + ext end desc 'Build packages' task :package => %w[.gem .tar.gz].map {|e| package(e)} desc 'Build and install as local gem' task :install => package('.gem') do sh "gem install #{package('.gem')}" end directory 'pkg/' file package('.gem') => %w[pkg/ tilt.gemspec] + SPEC.files do |f| sh "gem build tilt.gemspec" mv File.basename(f.name), f.name end file package('.tar.gz') => %w[pkg/] + SPEC.files do |f| sh "git archive --format=tar HEAD | gzip > #{f.name}" end desc 'Upload gem and tar.gz distributables to rubyforge' task :release => [package('.gem'), package('.tar.gz')] do |t| sh <<-SH rubyforge add_release sinatra tilt #{SPEC.version} #{package('.gem')} && rubyforge add_file sinatra tilt #{SPEC.version} #{package('.tar.gz')} SH end end # GEMSPEC =================================================================== file 'tilt.gemspec' => FileList['{lib,test}/**','Rakefile'] do |f| # read version from tilt.rb version = File.read('lib/tilt.rb')[/VERSION = '(.*)'/] && $1 # read spec file and split out manifest section spec = File. read(f.name). sub(/s\.version\s*=\s*'.*'/, "s.version = '#{version}'") parts = spec.split(" # = MANIFEST =\n") # determine file list from git ls-files files = `git ls-files -- lib bin COPYING`. split("\n").sort.reject{ |file| file =~ /^\./ }. map{ |file| " #{file}" }.join("\n") # piece file back together and write... parts[1] = " s.files = %w[\n#{files}\n ]\n" spec = parts.join(" # = MANIFEST =\n") spec.sub!(/s.date = '.*'/, "s.date = '#{Time.now.strftime("%Y-%m-%d")}'") File.open(f.name, 'w') { |io| io.write(spec) } puts "updated #{f.name}" end tilt-2.0.11/bin/000077500000000000000000000000001426657337700133435ustar00rootroot00000000000000tilt-2.0.11/bin/tilt000077500000000000000000000066051426657337700142540ustar00rootroot00000000000000#!/usr/bin/env ruby require 'ostruct' require 'optparse' require 'tilt' usage = < Process template and write output to stdout. With no or when is '-', read template from stdin and use the --type option to determine the template's type. Options -l, --list List template engines + file patterns and exit -t, --type= Use this template engine; required if no -y, --layout= Use as a layout template -D= Define variable as -d, --define-file= Load YAML from and use for variables --vars= Evaluate to Hash and use for variables -h, --help Show this help message Convert markdown to HTML: $ tilt foo.markdown > foo.html Process ERB template: $ echo "Answer: <%= 2 + 2 %>" | tilt -t erb Answer: 4 Define variables: $ echo "Answer: <%= 2 + n %>" | tilt -t erb --vars="{:n=>40}" Answer: 42 $ echo "Answer: <%= 2 + n.to_i %>" | tilt -t erb -Dn=40 Answer: 42 USAGE script_name = File.basename($0) pattern = nil layout = nil locals = {} ARGV.options do |o| o.program_name = script_name # list all available template engines o.on("-l", "--list") do groups = {} Tilt.lazy_map.each do |pattern,engines| engines.each do |engine| key = engine[0].split('::').last.sub(/Template$/, '') (groups[key] ||= []) << pattern end end groups.sort { |(k1,v1),(k2,v2)| k1 <=> k2 }.each do |engine,files| printf "%-15s %s\n", engine, files.sort.join(', ') end exit end # the template type / pattern o.on("-t", "--type=PATTERN", String) do |val| abort "unknown template type: #{val}" if Tilt[val].nil? pattern = val end # pass template output into the specified layout template o.on("-y", "--layout=FILE", String) do |file| paths = [file, "~/.tilt/#{file}", "/etc/tilt/#{file}"] layout = paths. map { |p| File.expand_path(p) }. find { |p| File.exist?(p) } abort "no such layout: #{file}" if layout.nil? end # define a local variable o.on("-D", "--define=PAIR", String) do |pair| key, value = pair.split(/[=:]/, 2) locals[key.to_sym] = value end # define local variables from YAML or JSON o.on("-d", "--define-file=FILE", String) do |file| require 'yaml' abort "no such define file: #{file}" unless File.exist? file hash = File.open(file, 'r:bom|utf-8') { |f| YAML.load f, file } abort "vars must be a Hash, not #{hash.inspect}" if !hash.is_a?(Hash) hash.each { |key, value| locals[key.to_sym] = value } end # define local variables using a Ruby hash o.on("--vars=RUBY") do |ruby| hash = eval(ruby) abort "vars must be a Hash, not #{hash.inspect}" if !hash.is_a?(Hash) hash.each { |key, value| locals[key.to_sym] = value } end o.on_tail("-h", "--help") { puts usage; exit } o.parse! end file = ARGV.first || '-' pattern = file if pattern.nil? abort "template type not given. see: #{$0} --help" if ['-', ''].include?(pattern) engine = Tilt[pattern] abort "template engine not found for: #{pattern}" if engine.nil? template = engine.new(file) { if file == '-' $stdin.read else File.read(file) end } output = template.render(self, locals) # process layout output = Tilt.new(layout).render(self, locals) { output } if layout $stdout.write(output) tilt-2.0.11/docs/000077500000000000000000000000001426657337700135235ustar00rootroot00000000000000tilt-2.0.11/docs/TEMPLATES.md000066400000000000000000000400701426657337700154040ustar00rootroot00000000000000Tilt Templates ============== (See for a rendered, HTML-version of this file). While all Tilt templates use the same basic interface for template loading and evaluation, each varies in its capabilities and available options. Detailed documentation on each supported template engine is provided below. There are also some file extensions that have several implementations (currently ERB and Markdown). These template classes have certain features which are guaranteed to work across all the implementations. If you wish to be compatible with all of these template classes, you should only depend on the cross-implementation features. * [ERB](#erb) - Generic ERB implementation (backed by erb.rb or Erubis) * [erb.rb](#erbrb) - `Tilt::ERBTemplate` * [Erubis](#erubis) - `Tilt::ErubisTemplate` * [Haml](#haml) - `Tilt::HamlTemplate` * [Liquid](#liquid) - `Tilt::LiquidTemplate` * Nokogiri - `Tilt::NokogiriTemplate` * Builder - `Tilt::BuilderTemplate` * Markaby - `Tilt::MarkabyTemplate` * [Radius](#radius) - `Tilt::RadiusTemplate` Tilt also includes support for CSS processors like [LessCSS][lesscss] and [Sass][sass], [CoffeeScript][coffee-script] and some simple text formats. * Less - `Tilt::LessTemplate` * Sass - `Tilt::SassTemplate` * Scss - `Tilt::ScssTemplate` * CoffeeScript - `Tilt::CoffeeScriptTemplate` * Literate CoffeeScript - `Tilt::CoffeeScriptLiterateTemplate` * LiveScript - `Tilt::LiveScriptTemplate` * [Textile](#redcloth) - `Tilt::RedClothTemplate` * reStructuredText - `Tilt::RstPandocTemplate` * Creole - `Tilt::CreoleTemplate` * [RDoc](#rdoc) - `Tilt::RDocTemplate` Tilt has extensive support for Markdown, backed by one of seven different implementations (depending on which are available on your system): * [Markdown](#markdown) - Generic Markdown implementation * [RDiscount](#rdiscount) - `Tilt::RDiscountTemplate` * Redcarpet - `Tilt::RedcarpetTemplate` * BlueCloth - `Tilt::BlueClothTemplate` * Kramdown - `Tilt::KramdownTemplate` * Pandoc - `Tilt::PandocTemplate` * CommonMarker - `Tilt::CommonMarkerTemplate` * Maruku - `Tilt::MarukuTemplate` ERB (`erb`, `rhtml`) -------------------- ERB is a simple but powerful template languge for Ruby. In Tilt it's backed by [Erubis](#erubis) (if installed on your system) or by [erb.rb](#erbrb) (which is included in Ruby's standard library). This documentation applies to both implementations. ### Example Hello <%= world %>! ### Usage ERB templates support custom evaluation scopes and locals: >> require 'erb' >> template = Tilt.new('hello.html.erb') >> template.render(self, :world => 'World!') => "Hello World!" Or, use `Tilt['erb']` directly to process strings: template = Tilt['erb'].new { "Hello <%= world %>!" } template.render(self, :world => 'World!') ### Options #### `:trim => trim` Omits newlines and spaces around certain lines (usually those that starts with `<%` and ends with `%>`). There isn't a specification for how trimming in ERB should work, so if you need more control over the whitespace, you should use [erb.rb](#erbrb) or [Erubis](#erubis) directly. #### `:outvar => '_erbout'` The name of the variable used to accumulate template output. This can be any valid Ruby expression but must be assignable. By default a local variable named `_erbout` is used. erb.rb (`erb`, `rhtml`) ----------------------- [ERB](#erb) implementation available in Ruby's standard library. All the documentation of [ERB](#erb) applies in addition to the following: ### Usage The `Tilt::ERBTemplate` class is registered for all files ending in `.erb` or `.rhtml` by default, but with a *lower* priority than ErubisTemplate. If you specifically want to use ERB, it's recommended to use `#prefer`: Tilt.prefer Tilt::ERBTemplate __NOTE:__ It's suggested that your program `require 'erb'` at load time when using this template engine within a threaded environment. ### Options #### `:trim => true` The ERB trim mode flags. This is a string consisting of any combination of the following characters: * `'>'` omits newlines for lines ending in `>` * `'<>'` omits newlines for lines starting with `<%` and ending in `%>` * `'%'` enables processing of lines beginning with `%` * `true` is an alias of `<>` #### `:safe => nil` The `$SAFE` level; when set, ERB code will be run in a separate thread with `$SAFE` set to the provided level. #### `:outvar => '_erbout'` The name of the variable used to accumulate template output. This can be any valid Ruby expression but must be assignable. By default a local variable named `_erbout` is used. ### See also * [ERB documentation](http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html) Erubis (`erb`, `rhtml`, `erubis`) --------------------------------- [Erubis][erubis] is a fast, secure, and very extensible implementation of [ERB](#erb). All the documentation of [ERB](#erb) applies in addition to the following: ### Usage The `Tilt::ErubisTemplate` class is registered for all files ending in `.erb` or `.rhtml` by default, but with a *higher* priority than `ERBTemplate`. If you specifically want to use Erubis, it's recommended to use `#prefer`: Tilt.prefer Tilt::ErubisTemplate __NOTE:__ It's suggested that your program `require 'erubis'` at load time when using this template engine within a threaded environment. ### Options #### `:engine_class => Erubis::Eruby` Allows you to specify a custom engine class to use instead of the default which is `Erubis::Eruby`. #### `:escape_html => false` When `true`, `Erubis::EscapedEruby` will be used as the engine class instead of the default. All content within `<%= %>` blocks will be automatically html escaped. #### `:outvar => '_erbout'` The name of the variable used to accumulate template output. This can be any valid Ruby expression but must be assignable. By default a local variable named `_erbout` is used. #### `:pattern => '<% %>'` Set pattern for embedded Ruby code. #### `:trim => true` Delete spaces around `<% %>`. (But, spaces around `<%= %>` are preserved.) ### See also * [Erubis Home][erubis] * [Erubis User's Guide](http://www.kuwata-lab.com/erubis/users-guide.html) Haml (`haml`) ------------- [Haml][haml] is a markup language that’s used to cleanly and simply describe the HTML of any web document without the use of inline code. Haml functions as a replacement for inline page templating systems such as PHP, ASP, and ERB, the templating language used in most Ruby on Rails applications. However, Haml avoids the need for explicitly coding HTML into the template, because it itself is a description of the HTML, with some code to generate dynamic content. ([more](http://haml.info/about.html)) ### Example %html %head %title= @title %body %h1 Hello = world + '!' ### Usage The `Tilt::HamlTemplate` class is registered for all files ending in `.haml` by default. Haml templates support custom evaluation scopes and locals: >> require 'haml' >> template = Tilt.new('hello.haml') => # >> @title = "Hello Haml!" >> template.render(self, :world => 'Haml!') => " Hello Haml!

Hello Haml!

" Or, use the `Tilt::HamlTemplate` class directly to process strings: >> require 'haml' >> template = Tilt::HamlTemplate.new { "%h1= 'Hello Haml!'" } => # >> template.render => "

Hello Haml!

" __NOTE:__ It's suggested that your program `require 'haml'` at load time when using this template engine within a threaded environment. ### Options Please see the [Haml Reference](http://haml.info/docs/yardoc/file.HAML_REFERENCE.html#options) for all available options. ### See also * [#haml.docs](http://haml.info/docs.html) * [Haml Tutorial](http://haml.info/tutorial.html) * [Haml Reference](http://haml.info/docs/yardoc/file.HAML_REFERENCE.html) Liquid (`liquid`) ----------------- [Liquid][liquid] is for rendering safe templates which cannot affect the security of the server they are rendered on. ### Example {{ title }}

Hello {{ world }}!

### Usage `Tilt::LiquidTemplate` is registered for all files ending in `.liquid` by default. Liquid templates support locals and objects that respond to `#to_h` as scopes: >> require 'liquid' >> require 'tilt' >> template = Tilt.new('hello.liquid') => # >> scope = { :title => "Hello Liquid Templates" } >> template.render(nil, :world => "Liquid") => " Hello Liquid Templates

Hello Liquid!

" Or, use `Tilt::LiquidTemplate` directly to process strings: >> require 'liquid' >> template = Tilt::LiquidTemplate.new { "

Hello Liquid!

" } => # >> template.render => "

Hello Liquid!

" __NOTE:__ It's suggested that your program `require 'liquid'` at load time when using this template engine within a threaded environment. ### See also * [Liquid for Programmers](https://wiki.github.com/Shopify/liquid/liquid-for-programmers) * [Liquid Docs](http://liquid.rubyforge.org/) * GitHub: [Shopify/liquid](https://github.com/Shopify/liquid/) Radius (`radius`) ----------------- [Radius][radius] is the template language used by [Radiant CMS][radiant]. It is a tag language designed to be valid XML/HTML. ### Example

  • !
### Usage To render a template such as the one above. scope = OpenStruct.new scope.title = "Radius Example" scope.hello = "Hello, World!" require 'radius' template = Tilt::RadiusTemplate.new('example.radius', :tag_prefix=>'r') template.render(scope, :type=>'hlist'){ "Jackpot!" } The result will be:

Radius Example

  • Hello, World!
  • Hello, World!
  • Hello, World!
Jackpot! ### See also * [Radius][radius] * [Radiant CMS][radiant] Textile (`textile`) ------------------- Textile is a lightweight markup language originally developed by Dean Allen and billed as a "humane Web text generator". Textile converts its marked-up text input to valid, well-formed XHTML and also inserts character entity references for apostrophes, opening and closing single and double quotation marks, ellipses and em dashes. Textile formatted texts are converted to HTML with the [RedCloth][redcloth] engine, which is a Ruby extension written in C. ### Example h1. Hello Textile Templates Hello World. This is a paragraph. ### Usage __NOTE:__ It's suggested that your program `require 'redcloth'` at load time when using this template engine in a threaded environment. ### See Also * [RedCloth][redcloth] reStructuredText (`rst`) ------------------- reStructuredText is a lightweight markup language originally developed by David Goodger, based on StructuredText and Setext. reStructuredText is primarily used for technical documentation in the Python programming language community, e.g. by the [Sphinx](http://www.sphinx-doc.org/en/stable/rest.html) Python documentation generator. reStructuredText formatted texts are converted to HTML with [Pandoc][pandoc], which is an application written in Haskell, with a Ruby wrapper provided by the [pandoc-ruby][pandoc-ruby] gem. ### Example Hello Rst Templates =================== Hello World. This is a paragraph. ### See Also * [Pandoc][pandoc] * [pandoc-ruby][pandoc-ruby] RDoc (`rdoc`) ------------- [RDoc][rdoc] is the simple text markup system that comes with Ruby's standard library. ### Example = Hello RDoc Templates Hello World. This is a paragraph. ### Usage __NOTE:__ It's suggested that your program `require 'rdoc'`, `require 'rdoc/markup'`, and `require 'rdoc/markup/to_html'` at load time when using this template engine in a threaded environment. ### See also * [RDoc][rdoc] Markdown (`markdown`, `md`, `mkd`) ---------------------------------- [Markdown][markdown] is a lightweight markup language, created by John Gruber and Aaron Swartz. For any markup that is not covered by Markdown’s syntax, HTML is used. Marking up plain text with Markdown markup is easy and Markdown formatted texts are readable. Markdown formatted texts are converted to HTML with one of these libraries: * [RDiscount](#rdiscount) - `Tilt::RDiscountTemplate` * Redcarpet - `Tilt::RedcarpetTemplate` * BlueCloth - `Tilt::BlueClothTemplate` * Kramdown - `Tilt::KramdownTemplate` * Pandoc - `Tilt::PandocTemplate` * Maruku - `Tilt::MarukuTemplate` * CommonMarker - `Tilt::CommonMarkerTemplate` ### Example Hello Markdown Templates ======================== Hello World. This is a paragraph. ### Usage To wrap a Markdown formatted document with a layout: layout = Tilt['erb'].new do "<%= yield %>" end data = Tilt['md'].new { "# hello tilt" } layout.render { data.render } # => "

hello tilt

\n" ### Options Every implementation of Markdown *should* support these options, but there are some known problems with the Kramdown and Maruku engines. #### `:smartypants => true|false` Set `true` to enable [Smarty Pants][smartypants] style punctuation replacement. In Kramdown this option only applies to smart quotes. It will apply a subset of Smarty Pants (e.g. `...` to `…`) regardless of any option. Maruku ignores this option and always applies smart quotes (and nothing else). #### `:escape_html => true|false` Set `true` disallow raw HTML in Markdown contents. HTML is converted to literal text by escaping `<` characters. Kramdown and Maruku don't support this option. ### See also * [Markdown Syntax Documentation](http://daringfireball.net/projects/markdown/syntax) RDiscount (`markdown`, `md`, `mkd`) ----------------------------------- [Discount][discount] is an implementation of the Markdown markup language in C. [RDiscount][rdiscount] is a Ruby wrapper around Discount. All the documentation of [Markdown](#markdown) applies in addition to the following: ### Usage The `Tilt::RDiscountTemplate` class is registered for all files ending in `.markdown`, `.md` or `.mkd` by default with the highest priority. If you specifically want to use RDiscount, it's recommended to use `#prefer`: Tilt.prefer Tilt::RDiscountTemplate __NOTE:__ It's suggested that your program `require 'erubis'` at load time when using this template engine within a threaded environment. ### See also * [Discount][discount] * [RDiscount][rdiscount] * GitHub: [rtomayko/rdiscount][rdiscount] [lesscss]: http://lesscss.org/ "Less CSS" [sass]: http://sass-lang.com/ "Sass" [coffee-script]: http://jashkenas.github.com/coffee-script/ "Coffee Script" [erubis]: http://www.kuwata-lab.com/erubis/ "Erubis" [haml]: http://haml.info/ "Haml" [liquid]: http://www.liquidmarkup.org/ "Liquid" [radius]: http://radius.rubyforge.org/ "Radius" [radiant]: http://radiantcms.org/ "Radiant CMS" [redcloth]: http://redcloth.org/ "RedCloth" [rdoc]: http://rdoc.rubyforge.org/ "RDoc" [discount]: http://www.pell.portland.or.us/~orc/Code/discount/ "Discount" [rdiscount]: http://github.com/rtomayko/rdiscount/ "RDiscount" [smartypants]: http://daringfireball.net/projects/smartypants/ "Smarty Pants" [markdown]: http://en.wikipedia.org/wiki/Markdown "Markdown" [pandoc]: http://pandoc.org/ "Pandoc" [pandoc-ruby]: https://github.com/alphabetum/pandoc-ruby "pandoc-ruby" tilt-2.0.11/docs/common.css000066400000000000000000000002101426657337700155160ustar00rootroot00000000000000body { line-height: 1.5; font-size: 14px; } .frames #content { margin: 0; } #content { margin: 0 auto; max-width: 720px; } tilt-2.0.11/lib/000077500000000000000000000000001426657337700133415ustar00rootroot00000000000000tilt-2.0.11/lib/tilt.rb000066400000000000000000000142661426657337700146530ustar00rootroot00000000000000require 'tilt/mapping' require 'tilt/template' # Namespace for Tilt. This module is not intended to be included anywhere. module Tilt # Current version. VERSION = '2.0.11' @default_mapping = Mapping.new # @return [Tilt::Mapping] the main mapping object def self.default_mapping @default_mapping end # @private def self.lazy_map default_mapping.lazy_map end # @see Tilt::Mapping#register def self.register(template_class, *extensions) default_mapping.register(template_class, *extensions) end # @see Tilt::Mapping#register_lazy def self.register_lazy(class_name, file, *extensions) default_mapping.register_lazy(class_name, file, *extensions) end # @deprecated Use {register} instead. def self.prefer(template_class, *extensions) register(template_class, *extensions) end # @see Tilt::Mapping#registered? def self.registered?(ext) default_mapping.registered?(ext) end # @see Tilt::Mapping#new def self.new(file, line=nil, options={}, &block) default_mapping.new(file, line, options, &block) end # @see Tilt::Mapping#[] def self.[](file) default_mapping[file] end # @see Tilt::Mapping#template_for def self.template_for(file) default_mapping.template_for(file) end # @see Tilt::Mapping#templates_for def self.templates_for(file) default_mapping.templates_for(file) end # @return the template object that is currently rendering. # # @example # tmpl = Tilt['index.erb'].new { '<%= Tilt.current_template %>' } # tmpl.render == tmpl.to_s # # @note This is currently an experimental feature and might return nil # in the future. def self.current_template Thread.current[:tilt_current_template] end # Extremely simple template cache implementation. Calling applications # create a Tilt::Cache instance and use #fetch with any set of hashable # arguments (such as those to Tilt.new): # # cache = Tilt::Cache.new # cache.fetch(path, line, options) { Tilt.new(path, line, options) } # # Subsequent invocations return the already loaded template object. # # @note # Tilt::Cache is a thin wrapper around Hash. It has the following # limitations: # * Not thread-safe. # * Size is unbounded. # * Keys are not copied defensively, and should not be modified after # being passed to #fetch. More specifically, the values returned by # key#hash and key#eql? should not change. # If this is too limiting for you, use a different cache implementation. class Cache def initialize @cache = {} end # Caches a value for key, or returns the previously cached value. # If a value has been previously cached for key then it is # returned. Otherwise, block is yielded to and its return value # which may be nil, is cached under key and returned. # @yield # @yieldreturn the value to cache for key def fetch(*key) @cache.fetch(key) do @cache[key] = yield end end # Clears the cache. def clear @cache = {} end end # Template Implementations ================================================ # ERB register_lazy :ERBTemplate, 'tilt/erb', 'erb', 'rhtml' register_lazy :ErubisTemplate, 'tilt/erubis', 'erb', 'rhtml', 'erubis' register_lazy :ErubiTemplate, 'tilt/erubi', 'erb', 'rhtml', 'erubi' # Markdown register_lazy :BlueClothTemplate, 'tilt/bluecloth', 'markdown', 'mkd', 'md' register_lazy :MarukuTemplate, 'tilt/maruku', 'markdown', 'mkd', 'md' register_lazy :KramdownTemplate, 'tilt/kramdown', 'markdown', 'mkd', 'md' register_lazy :RDiscountTemplate, 'tilt/rdiscount', 'markdown', 'mkd', 'md' register_lazy :RedcarpetTemplate, 'tilt/redcarpet', 'markdown', 'mkd', 'md' register_lazy :CommonMarkerTemplate, 'tilt/commonmarker', 'markdown', 'mkd', 'md' register_lazy :PandocTemplate, 'tilt/pandoc', 'markdown', 'mkd', 'md' # Rest (sorted by name) register_lazy :AsciidoctorTemplate, 'tilt/asciidoc', 'ad', 'adoc', 'asciidoc' register_lazy :BabelTemplate, 'tilt/babel', 'es6', 'babel', 'jsx' register_lazy :BuilderTemplate, 'tilt/builder', 'builder' register_lazy :CSVTemplate, 'tilt/csv', 'rcsv' register_lazy :CoffeeScriptTemplate, 'tilt/coffee', 'coffee' register_lazy :CoffeeScriptLiterateTemplate, 'tilt/coffee', 'litcoffee' register_lazy :CreoleTemplate, 'tilt/creole', 'wiki', 'creole' register_lazy :EtanniTemplate, 'tilt/etanni', 'etn', 'etanni' register_lazy :HamlTemplate, 'tilt/haml', 'haml' register_lazy :LessTemplate, 'tilt/less', 'less' register_lazy :LiquidTemplate, 'tilt/liquid', 'liquid' register_lazy :LiveScriptTemplate, 'tilt/livescript','ls' register_lazy :MarkabyTemplate, 'tilt/markaby', 'mab' register_lazy :NokogiriTemplate, 'tilt/nokogiri', 'nokogiri' register_lazy :PlainTemplate, 'tilt/plain', 'html' register_lazy :PrawnTemplate, 'tilt/prawn', 'prawn' register_lazy :RDocTemplate, 'tilt/rdoc', 'rdoc' register_lazy :RadiusTemplate, 'tilt/radius', 'radius' register_lazy :RedClothTemplate, 'tilt/redcloth', 'textile' register_lazy :RstPandocTemplate, 'tilt/rst-pandoc', 'rst' register_lazy :SassTemplate, 'tilt/sass', 'sass' register_lazy :ScssTemplate, 'tilt/sass', 'scss' register_lazy :SigilTemplate, 'tilt/sigil', 'sigil' register_lazy :StringTemplate, 'tilt/string', 'str' register_lazy :TypeScriptTemplate, 'tilt/typescript', 'ts', 'tsx' register_lazy :WikiClothTemplate, 'tilt/wikicloth', 'wiki', 'mediawiki', 'mw' register_lazy :YajlTemplate, 'tilt/yajl', 'yajl' # External template engines register_lazy 'Slim::Template', 'slim', 'slim' register_lazy 'Tilt::HandlebarsTemplate', 'tilt/handlebars', 'handlebars', 'hbs' register_lazy 'Tilt::OrgTemplate', 'org-ruby', 'org' register_lazy 'Tilt::EmacsOrgTemplate', 'tilt/emacs_org', 'org' register_lazy 'Opal::Processor', 'opal', 'opal', 'rb' register_lazy 'Tilt::JbuilderTemplate', 'tilt/jbuilder', 'jbuilder' end tilt-2.0.11/lib/tilt/000077500000000000000000000000001426657337700143155ustar00rootroot00000000000000tilt-2.0.11/lib/tilt/asciidoc.rb000066400000000000000000000012421426657337700164170ustar00rootroot00000000000000require 'tilt/template' require 'asciidoctor' # AsciiDoc see: http://asciidoc.org/ module Tilt # Asciidoctor implementation for AsciiDoc see: # http://asciidoctor.github.com/ # # Asciidoctor is an open source, pure-Ruby processor for # converting AsciiDoc documents or strings into HTML 5, # DocBook 4.5 and other formats. class AsciidoctorTemplate < Template self.default_mime_type = 'text/html' def prepare options[:header_footer] = false if options[:header_footer].nil? end def evaluate(scope, locals, &block) @output ||= Asciidoctor.render(data, options, &block) end def allows_script? false end end end tilt-2.0.11/lib/tilt/babel.rb000066400000000000000000000005111426657337700157040ustar00rootroot00000000000000require 'tilt/template' require 'babel/transpiler' module Tilt class BabelTemplate < Template self.default_mime_type = 'application/javascript' def prepare options[:filename] ||= file end def evaluate(scope, locals, &block) @output ||= Babel::Transpiler.transform(data)["code"] end end end tilt-2.0.11/lib/tilt/bluecloth.rb000066400000000000000000000007031426657337700166230ustar00rootroot00000000000000require 'tilt/template' require 'bluecloth' module Tilt # BlueCloth Markdown implementation. See: # http://deveiate.org/projects/BlueCloth/ class BlueClothTemplate < Template self.default_mime_type = 'text/html' def prepare @engine = BlueCloth.new(data, options) @output = nil end def evaluate(scope, locals, &block) @output ||= @engine.to_html end def allows_script? false end end end tilt-2.0.11/lib/tilt/builder.rb000066400000000000000000000013271426657337700162730ustar00rootroot00000000000000require 'tilt/template' require 'builder' module Tilt # Builder template implementation. See: # http://builder.rubyforge.org/ class BuilderTemplate < Template self.default_mime_type = 'text/xml' def prepare options[:indent] ||= 2 end def evaluate(scope, locals, &block) xml = (locals[:xml] || ::Builder::XmlMarkup.new(options)) if data.respond_to?(:to_str) if !locals[:xml] locals = locals.merge(:xml => xml) end return super(scope, locals, &block) end data.call(xml) xml.target! end def precompiled_postamble(locals) "xml.target!" end def precompiled_template(locals) data.to_str end end end tilt-2.0.11/lib/tilt/coffee.rb000066400000000000000000000021611426657337700160710ustar00rootroot00000000000000require 'tilt/template' require 'coffee_script' module Tilt # CoffeeScript template implementation. See: # http://coffeescript.org/ # # CoffeeScript templates do not support object scopes, locals, or yield. class CoffeeScriptTemplate < 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 # DEPRECATED def self.default_no_wrap @@default_bare end # DEPRECATED def self.default_no_wrap=(value) @@default_bare = value end def self.literate? false end def prepare if !options.key?(:bare) and !options.key?(:no_wrap) options[:bare] = self.class.default_bare end options[:literate] ||= self.class.literate? end def evaluate(scope, locals, &block) @output ||= CoffeeScript.compile(data, options) end def allows_script? false end end class CoffeeScriptLiterateTemplate < CoffeeScriptTemplate def self.literate? true end end end tilt-2.0.11/lib/tilt/commonmarker.rb000066400000000000000000000033451426657337700173410ustar00rootroot00000000000000require 'tilt/template' require 'commonmarker' module Tilt class CommonMarkerTemplate < Template self.default_mime_type = 'text/html' OPTION_ALIAS = { :smartypants => :SMART } PARSE_OPTIONS = [ :FOOTNOTES, :LIBERAL_HTML_TAG, :SMART, :smartypants, :STRIKETHROUGH_DOUBLE_TILDE, :UNSAFE, :VALIDATE_UTF8, ].freeze RENDER_OPTIONS = [ :FOOTNOTES, :FULL_INFO_STRING, :GITHUB_PRE_LANG, :HARDBREAKS, :NOBREAKS, :SAFE, # Removed in v0.18.0 (2018-10-17) :SOURCEPOS, :TABLE_PREFER_STYLE_ATTRIBUTES, :UNSAFE, ].freeze EXTENSIONS = [ :autolink, :strikethrough, :table, :tagfilter, :tasklist, ].freeze def extensions EXTENSIONS.select do |extension| options[extension] end end def parse_options raw_options = PARSE_OPTIONS.select do |option| options[option] end actual_options = raw_options.map do |option| OPTION_ALIAS[option] || option end if actual_options.any? actual_options else :DEFAULT end end def render_options raw_options = RENDER_OPTIONS.select do |option| options[option] end actual_options = raw_options.map do |option| OPTION_ALIAS[option] || option end if actual_options.any? actual_options else :DEFAULT end end def prepare @engine = nil @output = nil end def evaluate(scope, locals, &block) doc = CommonMarker.render_doc(data, parse_options, extensions) doc.to_html(render_options, extensions) end def allows_script? false end end end tilt-2.0.11/lib/tilt/creole.rb000066400000000000000000000007761426657337700161250ustar00rootroot00000000000000require 'tilt/template' require 'creole' module Tilt # Creole implementation. See: # http://www.wikicreole.org/ class CreoleTemplate < Template def prepare opts = {} [:allowed_schemes, :extensions, :no_escape].each do |k| opts[k] = options[k] if options[k] end @engine = Creole::Parser.new(data, opts) @output = nil end def evaluate(scope, locals, &block) @output ||= @engine.to_html end def allows_script? false end end end tilt-2.0.11/lib/tilt/csv.rb000066400000000000000000000024301426657337700154340ustar00rootroot00000000000000require 'tilt/template' if RUBY_VERSION >= '1.9.0' require 'csv' else require 'fastercsv' end module Tilt # CSV Template implementation. See: # http://ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV.html # # == Example # # # Example of csv template # tpl = <<-EOS # # header # csv << ['NAME', 'ID'] # # # data rows # @people.each do |person| # csv << [person[:name], person[:id]] # end # EOS # # @people = [ # {:name => "Joshua Peek", :id => 1}, # {:name => "Ryan Tomayko", :id => 2}, # {:name => "Simone Carletti", :id => 3} # ] # # template = Tilt::CSVTemplate.new { tpl } # template.render(self) # class CSVTemplate < Template self.default_mime_type = 'text/csv' def self.engine if RUBY_VERSION >= '1.9.0' && defined? ::CSV ::CSV elsif defined? ::FasterCSV ::FasterCSV end end def prepare @outvar = options.delete(:outvar) || '_csvout' end def precompiled_template(locals) <<-RUBY #{@outvar} = #{self.class.engine}.generate(**#{options}) do |csv| #{data} end RUBY end def precompiled(locals) source, offset = super [source, offset + 1] end end end tilt-2.0.11/lib/tilt/dummy.rb000066400000000000000000000001061426657337700157720ustar00rootroot00000000000000# Used for detecting autoloading bug in JRuby class Tilt::Dummy; end tilt-2.0.11/lib/tilt/erb.rb000066400000000000000000000032141426657337700154120ustar00rootroot00000000000000require 'tilt/template' require 'erb' module Tilt # ERB template implementation. See: # http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html class ERBTemplate < Template @@default_output_variable = '_erbout' SUPPORTS_KVARGS = ::ERB.instance_method(:initialize).parameters.assoc(:key) rescue false def self.default_output_variable @@default_output_variable end def self.default_output_variable=(name) warn "#{self}.default_output_variable= has been replaced with the :outvar-option" @@default_output_variable = name end def prepare @outvar = options[:outvar] || self.class.default_output_variable options[:trim] = '<>' if !(options[:trim] == false) && (options[:trim].nil? || options[:trim] == true) @engine = if SUPPORTS_KVARGS ::ERB.new(data, trim_mode: options[:trim], eoutvar: @outvar) else ::ERB.new(data, options[:safe], options[:trim], @outvar) end end def precompiled_template(locals) source = @engine.src source end def precompiled_preamble(locals) <<-RUBY begin __original_outvar = #{@outvar} if defined?(#{@outvar}) #{super} RUBY end def precompiled_postamble(locals) <<-RUBY #{super} ensure #{@outvar} = __original_outvar end RUBY end # ERB generates a line to specify the character coding of the generated # source in 1.9. Account for this in the line offset. if RUBY_VERSION >= '1.9.0' def precompiled(locals) source, offset = super [source, offset + 1] end end end end tilt-2.0.11/lib/tilt/erubi.rb000066400000000000000000000015661426657337700157600ustar00rootroot00000000000000require 'tilt/template' require 'erubi' module Tilt # Erubi (a simplified version of Erubis) template implementation. # See https://github.com/jeremyevans/erubi # # ErubiTemplate supports the following additional options, in addition # to the options supported by the Erubi engine: # # :engine_class :: allows you to specify a custom engine class to use # instead of the default (which is ::Erubi::Engine). class ErubiTemplate < Template def prepare @options.merge!(:preamble => false, :postamble => false, :ensure=>true) engine_class = @options[:engine_class] || Erubi::Engine @engine = engine_class.new(data, @options) @outvar = @engine.bufvar # Remove dup after tilt supports frozen source. @src = @engine.src.dup @engine end def precompiled_template(locals) @src end end end tilt-2.0.11/lib/tilt/erubis.rb000066400000000000000000000027071426657337700161410ustar00rootroot00000000000000require 'tilt/erb' require 'erubis' module Tilt # Erubis template implementation. See: # http://www.kuwata-lab.com/erubis/ # # ErubisTemplate supports the following additional options, which are not # passed down to the Erubis engine: # # :engine_class allows you to specify a custom engine class to use # instead of the default (which is ::Erubis::Eruby). # # :escape_html when true, ::Erubis::EscapedEruby will be used as # the engine class instead of the default. All content # within <%= %> blocks will be automatically html escaped. class ErubisTemplate < ERBTemplate def prepare @outvar = options.delete(:outvar) || self.class.default_output_variable @options.merge!(:preamble => false, :postamble => false, :bufvar => @outvar) engine_class = options.delete(:engine_class) engine_class = ::Erubis::EscapedEruby if options.delete(:escape_html) @engine = (engine_class || ::Erubis::Eruby).new(data, options) end def precompiled_preamble(locals) [super, "#{@outvar} = _buf = String.new"].join("\n") end def precompiled_postamble(locals) [@outvar, super].join("\n") end # Erubis doesn't have ERB's line-off-by-one under 1.9 problem. # Override and adjust back. if RUBY_VERSION >= '1.9.0' def precompiled(locals) source, offset = super [source, offset - 1] end end end end tilt-2.0.11/lib/tilt/etanni.rb000066400000000000000000000011161426657337700161170ustar00rootroot00000000000000require 'tilt/template' module Tilt class EtanniTemplate < Template def prepare separator = data.hash.abs chomp = "<<#{separator}.chomp!" start = "\n_out_ << #{chomp}\n" stop = "\n#{separator}\n" replacement = "#{stop}\\1#{start}" temp = data.strip temp.gsub!(/<\?r\s+(.*?)\s+\?>/m, replacement) @code = "_out_ = [<<#{separator}.chomp!]\n#{temp}#{stop}_out_.join" end def precompiled_template(locals) @code end def precompiled(locals) source, offset = super [source, offset + 1] end end end tilt-2.0.11/lib/tilt/haml.rb000066400000000000000000000052151426657337700155660ustar00rootroot00000000000000require 'tilt/template' require 'haml' module Tilt # Haml template implementation. See: # http://haml.hamptoncatlin.com/ class HamlTemplate < Template self.default_mime_type = 'text/html' # `Gem::Version.correct?` may return false because of Haml::VERSION #=> "3.1.8 (Separated Sally)". After Haml 4, it's always correct. if Gem::Version.correct?(Haml::VERSION) && Gem::Version.new(Haml::VERSION) >= Gem::Version.new('5.0.0.beta.2') def prepare options = {}.update(@options).update(filename: eval_file, line: line) if options.include?(:outvar) options[:buffer] = options.delete(:outvar) options[:save_buffer] = true end @engine = ::Haml::TempleEngine.new(options) @engine.compile(data) end def evaluate(scope, locals, &block) raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen? super end def precompiled_template(locals) @engine.precompiled_with_ambles( [], after_preamble: <<-RUBY __in_erb_template = true _haml_locals = locals RUBY ) end else # Following definitions are for Haml <= 4 and deprecated. def prepare options = @options.merge(:filename => eval_file, :line => line) @engine = ::Haml::Engine.new(data, options) end def evaluate(scope, locals, &block) raise ArgumentError, 'invalid scope: must not be frozen' if scope.frozen? if @engine.respond_to?(:precompiled_method_return_value, true) super else @engine.render(scope, locals, &block) end end # Precompiled Haml source. Taken from the precompiled_with_ambles # method in Haml::Precompiler: # http://github.com/nex3/haml/blob/master/lib/haml/precompiler.rb#L111-126 def precompiled_template(locals) @engine.precompiled end def precompiled_preamble(locals) local_assigns = super @engine.instance_eval do <<-RUBY begin extend Haml::Helpers _hamlout = @haml_buffer = Haml::Buffer.new(haml_buffer, #{options_for_buffer.inspect}) _erbout = _hamlout.buffer __in_erb_template = true _haml_locals = locals #{local_assigns} RUBY end end def precompiled_postamble(locals) @engine.instance_eval do <<-RUBY #{precompiled_method_return_value} ensure @haml_buffer = @haml_buffer.upper if haml_buffer end RUBY end end end end end tilt-2.0.11/lib/tilt/kramdown.rb000066400000000000000000000010021426657337700164550ustar00rootroot00000000000000require 'tilt/template' require 'kramdown' module Tilt # Kramdown Markdown implementation. See: # http://kramdown.rubyforge.org/ class KramdownTemplate < Template DUMB_QUOTES = [39, 39, 34, 34] def prepare options[:smart_quotes] = DUMB_QUOTES unless options[:smartypants] @engine = Kramdown::Document.new(data, options) @output = nil end def evaluate(scope, locals, &block) @output ||= @engine.to_html end def allows_script? false end end end tilt-2.0.11/lib/tilt/less.rb000066400000000000000000000012271426657337700156120ustar00rootroot00000000000000require 'tilt/template' require 'less' module Tilt # Lessscss template implementation. See: # http://lesscss.org/ # # Less templates do not support object scopes, locals, or yield. class LessTemplate < Template self.default_mime_type = 'text/css' def prepare if ::Less.const_defined? :Engine @engine = ::Less::Engine.new(data) else parser = ::Less::Parser.new(options.merge :filename => eval_file, :line => line) @engine = parser.parse(data) end end def evaluate(scope, locals, &block) @output ||= @engine.to_css(options) end def allows_script? false end end end tilt-2.0.11/lib/tilt/liquid.rb000066400000000000000000000023341426657337700161330ustar00rootroot00000000000000require 'tilt/template' require 'liquid' module Tilt # Liquid template implementation. See: # http://liquidmarkup.org/ # # Liquid is designed to be a *safe* template system and threfore # does not provide direct access to execuatable scopes. In order to # support a +scope+, the +scope+ must be able to represent itself # as a hash by responding to #to_h. If the +scope+ does not respond # to #to_h it will be ignored. # # LiquidTemplate does not support yield blocks. # # It's suggested that your program require 'liquid' at load # time when using this template engine. class LiquidTemplate < Template def prepare @engine = ::Liquid::Template.parse(data, liquid_options) end def evaluate(scope, locals, &block) locals = locals.inject({}){ |h,(k,v)| h[k.to_s] = v ; h } if scope.respond_to?(:to_h) scope = scope.to_h.inject({}){ |h,(k,v)| h[k.to_s] = v ; h } locals = scope.merge(locals) end locals['yield'] = block.nil? ? '' : yield locals['content'] = locals['yield'] @engine.render(locals) end def allows_script? false end private def liquid_options { line_numbers: true }.merge options end end end tilt-2.0.11/lib/tilt/livescript.rb000066400000000000000000000007371426657337700170350ustar00rootroot00000000000000require 'tilt/template' require 'livescript' module Tilt # LiveScript template implementation. See: # http://livescript.net/ # # LiveScript templates do not support object scopes, locals, or yield. class LiveScriptTemplate < Template self.default_mime_type = 'application/javascript' def prepare end def evaluate(scope, locals, &block) @output ||= LiveScript.compile(data, options) end def allows_script? false end end end tilt-2.0.11/lib/tilt/mapping.rb000066400000000000000000000221411426657337700162750ustar00rootroot00000000000000require 'monitor' module Tilt # Tilt::Mapping associates file extensions with template implementations. # # mapping = Tilt::Mapping.new # mapping.register(Tilt::RDocTemplate, 'rdoc') # mapping['index.rdoc'] # => Tilt::RDocTemplate # mapping.new('index.rdoc').render # # You can use {#register} to register a template class by file # extension, {#registered?} to see if a file extension is mapped, # {#[]} to lookup template classes, and {#new} to instantiate template # objects. # # Mapping also supports *lazy* template implementations. Note that regularly # registered template implementations *always* have preference over lazily # registered template implementations. You should use {#register} if you # depend on a specific template implementation and {#register_lazy} if there # are multiple alternatives. # # mapping = Tilt::Mapping.new # mapping.register_lazy('RDiscount::Template', 'rdiscount/template', 'md') # mapping['index.md'] # # => RDiscount::Template # # {#register_lazy} takes a class name, a filename, and a list of file # extensions. When you try to lookup a template name that matches the # file extension, Tilt will automatically try to require the filename and # constantize the class name. # # Unlike {#register}, there can be multiple template implementations # registered lazily to the same file extension. Tilt will attempt to load the # template implementations in order (registered *last* would be tried first), # returning the first which doesn't raise LoadError. # # If all of the registered template implementations fails, Tilt will raise # the exception of the first, since that was the most preferred one. # # mapping = Tilt::Mapping.new # mapping.register_lazy('Bluecloth::Template', 'bluecloth/template', 'md') # mapping.register_lazy('RDiscount::Template', 'rdiscount/template', 'md') # mapping['index.md'] # # => RDiscount::Template # # In the previous example we say that RDiscount has a *higher priority* than # BlueCloth. Tilt will first try to `require "rdiscount/template"`, falling # back to `require "bluecloth/template"`. If none of these are successful, # the first error will be raised. class Mapping # @private attr_reader :lazy_map, :template_map def initialize @template_map = Hash.new @lazy_map = Hash.new { |h, k| h[k] = [] } end # @private def initialize_copy(other) @template_map = other.template_map.dup @lazy_map = other.lazy_map.dup end # Registers a lazy template implementation by file extension. You # can have multiple lazy template implementations defined on the # same file extension, in which case the template implementation # defined *last* will be attempted loaded *first*. # # @param class_name [String] Class name of a template class. # @param file [String] Filename where the template class is defined. # @param extensions [Array] List of extensions. # @return [void] # # @example # mapping.register_lazy 'MyEngine::Template', 'my_engine/template', 'mt' # # defined?(MyEngine::Template) # => false # mapping['index.mt'] # => MyEngine::Template # defined?(MyEngine::Template) # => true def register_lazy(class_name, file, *extensions) # Internal API if class_name.is_a?(Symbol) Tilt.autoload class_name, file class_name = "Tilt::#{class_name}" end extensions.each do |ext| @lazy_map[ext].unshift([class_name, file]) end end # Registers a template implementation by file extension. There can only be # one template implementation per file extension, and this method will # override any existing mapping. # # @param template_class # @param extensions [Array] List of extensions. # @return [void] # # @example # mapping.register MyEngine::Template, 'mt' # mapping['index.mt'] # => MyEngine::Template def register(template_class, *extensions) if template_class.respond_to?(:to_str) # Support register(ext, template_class) too extensions, template_class = [template_class], extensions[0] end extensions.each do |ext| @template_map[ext.to_s] = template_class end end # Checks if a file extension is registered (either eagerly or # lazily) in this mapping. # # @param ext [String] File extension. # # @example # mapping.registered?('erb') # => true # mapping.registered?('nope') # => false def registered?(ext) @template_map.has_key?(ext.downcase) or lazy?(ext) end # Instantiates a new template class based on the file. # # @raise [RuntimeError] if there is no template class registered for the # file name. # # @example # mapping.new('index.mt') # => instance of MyEngine::Template # # @see Tilt::Template.new def new(file, line=nil, options={}, &block) if template_class = self[file] template_class.new(file, line, options, &block) else fail "No template engine registered for #{File.basename(file)}" end end # Looks up a template class based on file name and/or extension. # # @example # mapping['views/hello.erb'] # => Tilt::ERBTemplate # mapping['hello.erb'] # => Tilt::ERBTemplate # mapping['erb'] # => Tilt::ERBTemplate # # @return [template class] def [](file) _, ext = split(file) ext && lookup(ext) end alias template_for [] # Looks up a list of template classes based on file name. If the file name # has multiple extensions, it will return all template classes matching the # extensions from the end. # # @example # mapping.templates_for('views/index.haml.erb') # # => [Tilt::ERBTemplate, Tilt::HamlTemplate] # # @return [Array