From acedfcfb4a42f6a311120d96d09b9ce4dcf2a9e6 Mon Sep 17 00:00:00 2001 From: Niklaus Giger Date: Wed, 14 Feb 2018 17:06:55 +0100 Subject: [PATCH] Inline css/javascript files if possible Signed-off-by: Niklaus Giger --- History.md | 6 +++++ doc/test/inline.css | 1 + lib/htmlgrid/dojotoolkit.rb | 2 ++ lib/htmlgrid/version.rb | 2 +- test/test_dojotoolkit.rb | 59 +++++++++++++++++++++++++++++++++++++++++++++ test/test_template.rb | 2 ++ 6 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 doc/test/inline.css diff --git a/History.md b/History.md index 0a26b4c..5594e37 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,9 @@ +# 1.1.5 / 14.02.2018 + +* Inline *.css and *.js for faster loading. +** This works also when the css/js files are zippe +** But zipped css/js are unreadable via developert tools + # 1.1.4 / 19.04.2017 * Fix dynamic_html for MSIE browser diff --git a/doc/test/inline.css b/doc/test/inline.css new file mode 100644 index 0000000..f5111c6 --- /dev/null +++ b/doc/test/inline.css @@ -0,0 +1 @@ +/* this is a dummy CSS file, which should be inlined */ diff --git a/lib/htmlgrid/dojotoolkit.rb b/lib/htmlgrid/dojotoolkit.rb index 1ce2c68..b1518f1 100644 --- a/lib/htmlgrid/dojotoolkit.rb +++ b/lib/htmlgrid/dojotoolkit.rb @@ -110,8 +110,10 @@ module HtmlGrid 'text/javascript' => dojo_path, }.each do |type, path| if (content = get_inline(path)) + require 'pry'; binding.pry headers << context.style(:type =>type) { content } else + require 'pry'; binding.pry headers << context.style(:type =>type, :src => path) { "@import \"#{path}\";" } end end diff --git a/lib/htmlgrid/version.rb b/lib/htmlgrid/version.rb index 33644e9..0476ebb 100755 --- a/lib/htmlgrid/version.rb +++ b/lib/htmlgrid/version.rb @@ -1,5 +1,5 @@ #!/usr/bin/env ruby # encoding: utf-8 module HtmlGrid - VERSION = '1.1.4' + VERSION = '1.1.5' end diff --git a/test/test_dojotoolkit.rb b/test/test_dojotoolkit.rb index 53c9d84..8d2b688 100755 --- a/test/test_dojotoolkit.rb +++ b/test/test_dojotoolkit.rb @@ -30,6 +30,7 @@ require 'stub/cgi' require 'htmlgrid/dojotoolkit' require 'test_helper' require 'flexmock/minitest' +require 'sbsm/lookandfeel' class TestDojotoolkit < Minitest::Test class StubAttributeComponent < HtmlGrid::Component @@ -72,3 +73,61 @@ class TestDojotoolkit < Minitest::Test assert(/href="my_tooltip"/.match(result)) end end +class StubTemplateLookandfeel < SBSM::Lookandfeel + RESOURCES = { + :css => "test.css" + } + DICTIONARIES = { + "de" => { + :html_title => "Test", + } + } + def lookandfeel + self + end +end +class StubTemplateSession + def flavor + "gcc" + end + def language + "de" + end + def http_protocol + 'http' + end + def server_name + "testserver.com" + end + def server_port + '80' + end + alias :default_language :language +end +class PublicTemplate < HtmlGrid::Template + include HtmlGrid::DojoToolkit::DojoTemplate + COMPONENTS = {} + def dynamic_html_headers(context) + headers = super + end +end + +class TestTemplate < Minitest::Test + def setup + lookandfeel = StubTemplateLookandfeel.new(StubTemplateSession.new) + @template = PublicTemplate.new(nil, lookandfeel, nil) + end + def test_dynamic_html_headers + result = @template.to_html(CGI.new) +require 'pry'; binding.pry + + # @session.should_receive(:user_agent).and_return(nil) + comp = HtmlGrid::Component.new("foo", @session) + comp.dojo_tooltip = 'my_tooltip' + assert_equal("foo", comp.model) + assert_equal(false, comp.label?) + result= comp.to_html(@cgi) + require 'pry'; binding.pry + assert(/href="my_tooltip"/.match(result)) + end +end diff --git a/test/test_template.rb b/test/test_template.rb index 60e62b0..0436289 100755 --- a/test/test_template.rb +++ b/test/test_template.rb @@ -64,6 +64,7 @@ class StubTemplateLookandfeel < SBSM::Lookandfeel self end end + class Template < HtmlGrid::Template META_TAGS = [ { @@ -94,6 +95,7 @@ class TestTemplate < Minitest::Test '', ] expected.each_with_index { |line, idx| + require 'pry'; binding.pry unless result.index(line) assert(result.index(line), "#{idx} Missing: #{line} in #{result}") } end -- 2.14.2