mumuki-html-runner 1.6.2 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 300794e63c7cac26dd6c8f769f2e36002c7e867f779cf860c17b64479ed02848
4
- data.tar.gz: 9ffb85ae1c11f1f541e73181cd41e04e77bc2fa88ecfb69bd16e857e4ae01ae6
3
+ metadata.gz: fad781ed2ab0caedcb4dabf843978a196ab21e0180ff65a5bde3c949489bafb2
4
+ data.tar.gz: 54da7156d0c48c408fef086dcbb3ce09af5ff50298143acae7644c9615d60790
5
5
  SHA512:
6
- metadata.gz: b6a24b9db3a79f97793dec247313eb79961c6890e614767bbe5a0150fbc007701c8a305c0740a4d29d98a35ec18bafd3c7bf613fbb18062ff8281d931c82bce2
7
- data.tar.gz: 1012c8f4c91dbf9ab91616288df728a7ddee93ad904cf3efc9ab77e08998a3ee284c6fc23a8ae767690ced81a2e3cfe1169e0f0c123dad655a26d827c9abf0a2
6
+ metadata.gz: 1f8c4ed76589390f2d5627bf3afb2645762f647ff3f329b1d8852713bb313062dcc79b34d05ab9e2817856836aa04f7839f957557eea1d6086b64d1dea71b5ff
7
+ data.tar.gz: 5dc0746e3fe8ea912c5c90bc0a36f37c05441d869e418c705c95b1e048e038791c78f8cfd0a66f9763dbd38bace2e835d5d10ef7abd650a2773ef421cbc3202e
@@ -24,11 +24,11 @@ class HtmlExpectationsHook < Mumukit::Hook
24
24
  "Checker::#{lang}".constantize
25
25
  end
26
26
 
27
- def compile_content(request)
28
- request.content.presence || request.extra
29
- end
30
-
31
27
  def negate(expectation, matches)
32
28
  expectation.inspection.negated? ? matches.blank? : matches.present?
33
29
  end
30
+
31
+ def compile_content(request)
32
+ request.content.presence || request.extra
33
+ end
34
34
  end
@@ -0,0 +1,9 @@
1
+ class String
2
+ def escape_html
3
+ ERB::Util.html_escape self
4
+ end
5
+
6
+ def get_extension
7
+ self.split('.').last
8
+ end
9
+ end
data/lib/html_runner.rb CHANGED
@@ -11,9 +11,12 @@ Mumukit.configure do |config|
11
11
  config.content_type = 'html'
12
12
  config.process_expectations_on_empty_content = true
13
13
  config.run_test_hook_on_empty_test = true
14
+ config.multifile = true
14
15
  end
15
16
 
17
+ require_relative './extensions/string'
16
18
  require_relative './metadata_hook'
19
+ require_relative './precompile_hook'
17
20
  require_relative './test_hook'
18
21
  require_relative './checker'
19
22
  require_relative './expectations_hook'
@@ -0,0 +1,53 @@
1
+ class HtmlPrecompileHook < Mumukit::Templates::MultiFilePrecompileHook
2
+ VALID_EXTENSIONS = ['.html', '.js', '.css']
3
+
4
+ def main_file
5
+ 'index.html'
6
+ end
7
+
8
+ def consolidate(main_content, files)
9
+ files_by_extension = files.group_by { |file_name, _| file_name.get_extension }
10
+ files_by_extension.each { |extension, values| files_by_extension[extension] = values.to_h }
11
+
12
+ document = Nokogiri::HTML(main_content)
13
+ merge_script_tags! document, files_by_extension
14
+ merge_style_tags! document, files_by_extension
15
+
16
+ document.to_html
17
+ .gsub(/<!DOCTYPE[^>]+>/, '')
18
+ .gsub(/<meta[^>]+>/, '')
19
+ end
20
+
21
+ def files_of(request)
22
+ super(request).select { |file_name, _| valid_extension? file_name }
23
+ end
24
+
25
+ private
26
+
27
+ def valid_extension?(file_name)
28
+ VALID_EXTENSIONS.any? { |extension| file_name.end_with? extension }
29
+ end
30
+
31
+ def merge_script_tags!(document, files_by_extension)
32
+ document.xpath("//script").each { |tag| replace_script_tag! tag, files_by_extension }
33
+ end
34
+
35
+ def replace_script_tag!(tag, files_by_extension)
36
+ src = tag.get_attribute 'src'
37
+ file = files_by_extension.dig('js', src)
38
+ tag.replace("<script>#{file}</script>") if file.present?
39
+ end
40
+
41
+ def merge_style_tags!(document, files_by_extension)
42
+ document.xpath("//link").each { |tag| replace_style_tag! tag, files_by_extension }
43
+ end
44
+
45
+ def replace_style_tag!(tag, files_by_extension)
46
+ rel = tag.get_attribute 'rel'
47
+ return if rel != 'stylesheet'
48
+
49
+ href = tag.get_attribute 'href'
50
+ file = files_by_extension.dig('css', href)
51
+ tag.replace("<style>#{file}</style>") if file.present?
52
+ end
53
+ end
data/lib/test_hook.rb CHANGED
@@ -1,19 +1,11 @@
1
- require 'mumukit/hook'
2
-
3
- class String
4
- def escape_html
5
- ERB::Util.html_escape self
6
- end
7
- end
8
-
9
1
  class HtmlTestHook < Mumukit::Hook
10
2
  def compile(request)
11
3
  request
12
4
  end
13
5
 
14
6
  def run!(request)
15
- expected = request[:test]
16
- actual = request[:extra].presence || request[:content]
7
+ expected = request.test
8
+ actual = compile_content request
17
9
  if expected.blank? || contents_match?(expected, actual)
18
10
  [render_html(actual), :passed]
19
11
  else
@@ -21,6 +13,8 @@ class HtmlTestHook < Mumukit::Hook
21
13
  end
22
14
  end
23
15
 
16
+ private
17
+
24
18
  def contents_match?(expected, actual)
25
19
  hexp_without_blanks(expected) == hexp_without_blanks(actual)
26
20
  rescue
@@ -28,7 +22,7 @@ class HtmlTestHook < Mumukit::Hook
28
22
  end
29
23
 
30
24
  def hexp_without_blanks(content)
31
- hexp ["\r", "\n", "\t"]
25
+ hexp %W(\r \n \t)
32
26
  .reduce(content.strip) { |c, it| c.gsub(it, ' ') }
33
27
  .squeeze(' ')
34
28
  end
@@ -71,4 +65,7 @@ html
71
65
  html
72
66
  end
73
67
 
68
+ def compile_content(request)
69
+ request.extra.presence || request.content
70
+ end
74
71
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module HtmlVersionHook
2
- VERSION = '1.6.2'
2
+ VERSION = '1.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mumuki-html-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franco Leonardo Bulgarelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-22 00:00:00.000000000 Z
11
+ date: 2018-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.23'
19
+ version: '2.24'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.23'
26
+ version: '2.24'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hexp
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -147,10 +147,12 @@ files:
147
147
  - lib/checker/css.rb
148
148
  - lib/checker/html.rb
149
149
  - lib/expectations_hook.rb
150
+ - lib/extensions/string.rb
150
151
  - lib/html_runner.rb
151
152
  - lib/locales/en.yml
152
153
  - lib/locales/es.yml
153
154
  - lib/metadata_hook.rb
155
+ - lib/precompile_hook.rb
154
156
  - lib/test_hook.rb
155
157
  - lib/version.rb
156
158
  homepage: http://github.com/mumuki/mumuki-html-server