Skip to content
This repository

feature: add jst template file have cache #167

Open
wants to merge 21 commits into from
This page is out of date. Refresh to see the latest.
11 ext/jasmine-webkit-specrunner/Runner.cpp
@@ -66,7 +66,8 @@ void Runner::loadSpec()
66 66 QVectorIterator<QString> iterator(reportFiles);
67 67
68 68 while (iterator.hasNext()) {
69   - QFile *outputFile = new QFile(iterator.next());
  69 + QString fileName = iterator.next();
  70 + QFile *outputFile = new QFile(fileName);
70 71 outputFile->open(QIODevice::WriteOnly);
71 72 outputFiles.enqueue(outputFile);
72 73 }
@@ -157,6 +158,14 @@ void Runner::print(const QString &fh, const QString &content) {
157 158 }
158 159 }
159 160
  161 +void Runner::printFile(const QString &fileName, const QString &content) {
  162 + QFile *outputFile = new QFile(fileName);
  163 + outputFile->open(QIODevice::WriteOnly);
  164 + QTextStream ts(outputFile);
  165 + ts << qPrintable(content);
  166 + ts.flush();
  167 +}
  168 +
160 169 void Runner::finishSuite() {
161 170 isFinished = true;
162 171 runs = 0;
1  ext/jasmine-webkit-specrunner/Runner.h
@@ -40,6 +40,7 @@ class Runner: public QObject {
40 40 QString getSeed();
41 41
42 42 void print(const QString &fh, const QString &content);
  43 + void printFile(const QString &fileName, const QString &content);
43 44 void finishSuite();
44 45 void ping();
45 46
2  lib/jasmine/headless.rb
@@ -24,6 +24,7 @@ module Headless
24 24
25 25 autoload :CoffeeTemplate, 'jasmine/headless/coffee_template'
26 26 autoload :JSTemplate, 'jasmine/headless/js_template'
  27 + autoload :JSTTemplateCache, 'jasmine/headless/jst_template_cache'
27 28 autoload :JSTTemplate, 'jasmine/headless/jst_template'
28 29 autoload :CSSTemplate, 'jasmine/headless/css_template'
29 30 autoload :NilTemplate, 'jasmine/headless/nil_template'
@@ -58,4 +59,3 @@ def output
58 59 end
59 60
60 61 require 'jasmine/headless/errors'
61   -
16 lib/jasmine/headless/jst_template.rb
@@ -8,7 +8,21 @@ def evaluate(*args)
8 8 alert_bad_format(file)
9 9 return ''
10 10 end
11   - %{<script type="text/javascript">#{super}</script>}
  11 + begin
  12 + data = super
  13 + cache = Jasmine::Headless::JSTTemplateCache.new(file, data)
  14 +
  15 + source = cache.handle
  16 + if cache.cached?
  17 + %{<script type="text/javascript" src="#{cache.cache_file}"></script>
  18 + <script type="text/javascript">window.CSTF['#{File.split(cache.cache_file).last}'] = '#{file}';</script>}
  19 + else
  20 + %{<script type="text/javascript">#{source}</script>}
  21 + end
  22 + rescue StandardError => e
  23 + puts "[%s] Error in compiling file: %s" % [ 'jst'.color(:red), file.color(:yellow) ]
  24 + raise e
  25 + end
12 26 end
13 27 end
14 28 end
26 lib/jasmine/headless/jst_template_cache.rb
... ... @@ -0,0 +1,26 @@
  1 +require 'sprockets/jst_processor'
  2 +require 'digest/sha1'
  3 +require 'fileutils'
  4 +
  5 +module Jasmine
  6 + module Headless
  7 + class JSTTemplateCache < CacheableAction
  8 +
  9 + def initialize(file, data)
  10 + @file = file
  11 + @data = data
  12 + end
  13 +
  14 + class << self
  15 + def cache_type
  16 + "jst_template"
  17 + end
  18 + end
  19 +
  20 + def action
  21 + @data
  22 + end
  23 + end
  24 + end
  25 +end
  26 +
3  lib/jasmine/headless/template_writer.rb
@@ -49,7 +49,8 @@ def all_files
49 49 end
50 50
51 51 def jhw_reporters
52   - reporters.collect do |reporter, output|
  52 + reporters.collect do |reporter, report, output|
  53 + output = output || "spec/reports"
53 54 %{jasmine.getEnv().addReporter(new jasmine.HeadlessReporter.#{reporter}("#{output}"));}
54 55 end.join("\n")
55 56 end
1  skel/template.html.erb
@@ -68,7 +68,6 @@
68 68 checker();
69 69 });
70 70 }
71   -
72 71 jasmine.getEnv().execute();
73 72 }
74 73 </script>

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.