Class: QED::Script
- Inherits:
-
Object
- Object
- QED::Script
- Defined in:
- lib/qed/script.rb
Overview
Script
When run current working directory is changed to that of the demonstration script’s. So any relative file references within a demo must take that into account.
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Expanded dirname of
file
. -
#file ⇒ Object
readonly
Demonstration file.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #advice ⇒ Object
- #apply_environment ⇒ Object
-
#binding ⇒ Object
One binding per script.
-
#document ⇒ Object
Nokogiri HTML document.
- #environment ⇒ Object
-
#html ⇒ Object
Open, convert to HTML and cache.
-
#initialize(file, scope = nil) ⇒ Script
constructor
New Script.
-
#name ⇒ Object
File basename less extension.
-
#root ⇒ Object
Root node of the html document.
- #run(*observers) ⇒ Object
-
#to_html ⇒ Object
Open file and translate template into HTML text.
Constructor Details
Instance Attribute Details
#dir ⇒ Object (readonly)
Expanded dirname of file
.
25 26 27 |
# File 'lib/qed/script.rb', line 25 def dir @dir end |
#file ⇒ Object (readonly)
Demonstration file.
22 23 24 |
# File 'lib/qed/script.rb', line 22 def file @file end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
28 29 30 |
# File 'lib/qed/script.rb', line 28 def scope @scope end |
Instance Method Details
#advice ⇒ Object
43 44 45 |
# File 'lib/qed/script.rb', line 43 def advice @scope.__advice__ end |
#apply_environment ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/qed/script.rb', line 113 def apply_environment environment.each do |file| case File.extname(file) when '.rb' eval(File.read(file), scope.__binding__, file) else Script.new(file, scope).run end end end |
#binding ⇒ Object
One binding per script.
38 39 40 |
# File 'lib/qed/script.rb', line 38 def binding @binding ||= @scope.__binding__ end |
#document ⇒ Object
Nokogiri HTML document.
58 59 60 |
# File 'lib/qed/script.rb', line 58 def document @document ||= Nokogiri::HTML(to_html) end |
#environment ⇒ Object
107 108 109 110 |
# File 'lib/qed/script.rb', line 107 def environment glob = File.join(dir, '{environment,common,shared}', '*') Dir[glob] end |
#html ⇒ Object
Open, convert to HTML and cache.
83 84 85 |
# File 'lib/qed/script.rb', line 83 def html @html ||= to_html end |
#name ⇒ Object
File basename less extension.
53 54 55 |
# File 'lib/qed/script.rb', line 53 def name @name ||= File.basename(file).chomp(File.extname(file)) end |
#root ⇒ Object
Root node of the html document.
63 64 65 |
# File 'lib/qed/script.rb', line 63 def root document.root end |
#run(*observers) ⇒ Object
101 102 103 104 |
# File 'lib/qed/script.rb', line 101 def run(*observers) evaluator = Evaluator.new(self, *observers) evaluator.run end |
#to_html ⇒ Object
Open file and translate template into HTML text.
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/qed/script.rb', line 68 def to_html #case file #when /^http/ # ext = File.extname(file).sub('.','') # Tilt[ext].new{ source } #else #end if File.extname(file) == '.html' File.read(file) else Tilt.new(file).render end end |