Module: JadePug
- Extended by:
- Memoist
- Defined in:
- lib/pug-ruby.rb,
lib/jade-pug/base.rb,
lib/jade-pug/config.rb,
lib/jade-pug/compiler.rb,
lib/jade-pug/system-compiler.rb,
lib/jade-pug/shipped-compiler.rb,
lib/jade-pug/errors/compiler-error.rb,
lib/jade-pug/errors/compilation-error.rb
Overview
:nodoc:
Defined Under Namespace
Classes: CompilationError, Compiler, CompilerError, Config, ShippedCompiler, SystemCompiler
Instance Method Summary collapse
-
#compile(source, options = {}) ⇒ String
Compiles the template.
-
#compiler(wanted_version = version) ⇒ JadePug::Compiler
Returns engine compiler for given version.
-
#config ⇒ JadePug::Config
Returns config object for engine.
-
#did_switch_version(version_from, version_to) ⇒ nil
Executed after compiler version switched.
-
#echo(*messages) ⇒ nil
Prints messages.
-
#runtime_versions ⇒ Array<String>
Returns the list of all available engine runtime versions shipped with the gem.
-
#silence=(silence) ⇒ true, false
Turns the effect of #echo on or off.
-
#silence? ⇒ true, false
Returns true if #echo should print messages.
-
#sort_versions(versions) ⇒ Array<String>
private
Sorts versions in ascending order.
-
#system_version ⇒ String
Returns version for system-wide installed engine compiler.
-
#use(wanted_version) ⇒ String, :system
Switches compiler version.
-
#version ⇒ String, :system
private
Returns version of currently used engine compiler.
-
#versions ⇒ Array<String>
Returns the list of all available engine compiler versions shipped with the gem.
Instance Method Details
#compile(source, options = {}) ⇒ String
Compiles the template.
16 17 18 |
# File 'lib/jade-pug/base.rb', line 16 def compile(source, = {}) compiler.compile(source, ) end |
#compiler(wanted_version = version) ⇒ JadePug::Compiler
Returns engine compiler for given version. Compilers are cached.
26 27 28 29 30 31 32 33 |
# File 'lib/jade-pug/base.rb', line 26 def compiler(wanted_version = version) (@compilers ||= {})["#{ name }-#{ wanted_version }"] ||= begin case wanted_version when :system then self::SystemCompiler.new else self::ShippedCompiler.new(wanted_version) end end end |
#config ⇒ JadePug::Config
Returns config object for engine. Executed only once per engine (return value is memoized).
116 117 118 |
# File 'lib/jade-pug/base.rb', line 116 def config self::Config.new end |
#did_switch_version(version_from, version_to) ⇒ nil
Executed after compiler version switched. Outputs some useful information about version being used.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/jade-pug/base.rb', line 68 def did_switch_version(version_from, version_to) if version_from != version_to if Symbol === version_to echo "Using #{ version_to } #{ name }." else echo "Using #{ name } #{ version_to }. NOTE: Advanced features like includes, extends and blocks will not work." end end nil end |
#echo(*messages) ⇒ nil
Prints messages. By default messages are sent to the STDOUT by using Kernel#puts.
127 128 129 |
# File 'lib/jade-pug/base.rb', line 127 def echo(*) puts(*) unless silence? end |
#runtime_versions ⇒ Array<String>
Returns the list of all available engine runtime versions shipped with the gem.
95 96 97 98 99 100 |
# File 'lib/jade-pug/base.rb', line 95 def runtime_versions sort_versions(Dir[File.("../../../vendor/#{ name.downcase }-*.js", __FILE__)].map do |path| match = File.basename(path).match(/\A#{name.downcase}-runtime-(?<v>.+)\.js\z/) match[:v] if match end.compact) end |
#silence=(silence) ⇒ true, false
Turns the effect of #echo on or off.
136 137 138 |
# File 'lib/jade-pug/base.rb', line 136 def silence=(silence) @silence = !!silence end |
#silence? ⇒ true, false
Returns true if #echo should print messages. Otherwise returns false.
145 146 147 |
# File 'lib/jade-pug/base.rb', line 145 def silence? !!@silence end |
#sort_versions(versions) ⇒ Array<String> (private)
Sorts versions in ascending order.
175 176 177 |
# File 'lib/jade-pug/base.rb', line 175 def sort_versions(versions) versions.sort_by { |v| Gem::Version.new(v) } end |
#system_version ⇒ String
Returns version for system-wide installed engine compiler.
107 108 109 |
# File 'lib/jade-pug/base.rb', line 107 def system_version compiler(:system).version end |
#use(wanted_version) ⇒ String, :system
Switches compiler version.
-
If you want to switch compiler to one of that shipped with gem simple pass version as a string.
-
If you want to switch compiler to system pass :system as a version.
Pass block to temporarily switch the version. Without block the version is switched permanently.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/jade-pug/base.rb', line 46 def use(wanted_version) previous_version = version @version = wanted_version did_switch_version(previous_version, wanted_version) return @version unless block_given? begin yield ensure @version = previous_version did_switch_version(wanted_version, previous_version) end end |
#version ⇒ String, :system (private)
Returns version of currently used engine compiler. If no version has been set returns :system.
Only for internal usage.
To get the actual version of engine compiler refer to JadePug::Compiler#version.
Jade.compiler.version => "1.11.0"
160 161 162 163 164 165 166 |
# File 'lib/jade-pug/base.rb', line 160 def version if instance_variable_defined?(:@version) @version else :system end end |
#versions ⇒ Array<String>
Returns the list of all available engine compiler versions shipped with the gem.
83 84 85 86 87 88 |
# File 'lib/jade-pug/base.rb', line 83 def versions sort_versions(Dir[File.("../../../vendor/#{ name.downcase }-*.js", __FILE__)].map do |path| match = File.basename(path).match(/\A#{name.downcase}-(?!runtime-)(?<v>.+)\.min\.js\z/) match[:v] if match end.compact) end |