intranet-core 2.3.3 → 2.4.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 +4 -4
- data/lib/intranet/abstract_responder.rb +20 -6
- data/lib/intranet/core/builder.rb +3 -2
- data/lib/intranet/core/version.rb +1 -1
- data/lib/intranet/resources/haml/skeleton.haml +11 -13
- data/lib/intranet/resources/www/nav.js +9 -19
- data/spec/intranet/core_spec.rb +18 -10
- data/spec/test_responder/responder.rb +1 -11
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba7fae26118e05ab115341089026cbbff79721a77bccb8412a6db8713c048d36
|
4
|
+
data.tar.gz: d759168cea8f4500321fec20e1bd555a54033e1ccebbcdb335596b1b55c5b211
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c3c35cd768e6eed859d44343f40b93293ac3bd11f5b13cb9586e85cff96de7bef93a83774c5f2479397c15c16f2a3de0b571d3d5453454e847dbdff04ff4711
|
7
|
+
data.tar.gz: 7e26eb4903abd95964ae9ecf1f810d631043a92d32974ffbc81ee6ebf62c670b8427f65fb2feee6798899a18c542c40154acd26b7a77beecbe28a10cf23a40bc
|
@@ -37,30 +37,44 @@ module Intranet
|
|
37
37
|
# nothing to do
|
38
38
|
end
|
39
39
|
|
40
|
-
# Generates the HTML
|
40
|
+
# Generates the HTML answer (HTTP return code, MIME type and body) associated to the given
|
41
|
+
# +path+ and +query+.
|
42
|
+
#
|
43
|
+
# The function may return a partial content, in which case the HTTP return code must be 206 and
|
44
|
+
# the answer body is expected to be a +Hash+ with the following keys:
|
45
|
+
# * +:title+ (mandatory): the page title
|
46
|
+
# * +:content+ (mandatory): the partial content
|
47
|
+
# * +:stylesheets+ (optional): an array of the required Cascade Style Sheets (CSS) files, either
|
48
|
+
# absolute or relative to the module root
|
49
|
+
# * +:scripts+ (optional): an array of hashes, each representing a <script> element to be
|
50
|
+
# included in the generated page. Keys are the one accepted by the HTML <script> tag. The
|
51
|
+
# +:src+ key may be either absolute or relative to the module root
|
41
52
|
# @param path [String] The requested URI, relative to that module root URI
|
42
53
|
# @param query [Hash] The URI variable/value pairs, if any
|
43
|
-
# @return [Array
|
54
|
+
# @return [Array<Integer, String, String> or Array<Integer, String, Hash>] The HTTP return code,
|
55
|
+
# the MIME type and the answer body (partial if return code is 206).
|
44
56
|
def generate_page(path, query)
|
45
57
|
[404, '', '']
|
46
58
|
end
|
47
59
|
|
48
60
|
# Provides the list of Cascade Style Sheets (CSS) dependencies for this module, either using
|
49
61
|
# absolute or relative (from the module root) paths.
|
50
|
-
#
|
62
|
+
# @deprecated Use {generate_page} partial content feature, setting +:stylesheets+ attribute of
|
63
|
+
# the returned body.
|
51
64
|
# @return [Array] The list of CSS dependencies, as absolute path or relative to the module root
|
52
65
|
# URL.
|
53
66
|
def css_dependencies
|
54
|
-
[
|
67
|
+
[]
|
55
68
|
end
|
56
69
|
|
57
70
|
# Provides the list of Javascript files (JS) dependencies for this module, either using
|
58
71
|
# absolute or relative (from the module root) paths.
|
59
|
-
#
|
72
|
+
# @deprecated Use {generate_page} partial content feature, setting +:scripts+ attribute of the
|
73
|
+
# returned body.
|
60
74
|
# @return [Array] The list of JS dependencies, as absolute path or relative to the module root
|
61
75
|
# URL.
|
62
76
|
def js_dependencies
|
63
|
-
[
|
77
|
+
[]
|
64
78
|
end
|
65
79
|
end
|
66
80
|
end
|
@@ -117,8 +117,9 @@ module Intranet
|
|
117
117
|
# @param responder [Intranet::AbstractResponder] The responder that produced the body
|
118
118
|
# @param path [String] The path to the responder
|
119
119
|
def add_header_and_footer(body, responder, path)
|
120
|
-
|
121
|
-
|
120
|
+
body[:stylesheets] ||= responder.css_dependencies
|
121
|
+
body[:scripts] ||= responder.js_dependencies.map { |url| { src: url, defer: 'defer' } }
|
122
|
+
to_markup('skeleton', body: body, current_path: path)
|
122
123
|
end
|
123
124
|
|
124
125
|
# Check whether a path is valid. In particular, this function excludes a path containing an
|
@@ -4,23 +4,21 @@
|
|
4
4
|
%title= Socket.gethostname.capitalize + ' | ' + body[:title]
|
5
5
|
%meta{charset: 'utf-8'}
|
6
6
|
%link{rel: 'icon', type: 'image/x-icon', href: '/design/favicon.ico'}
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
-
|
13
|
-
-
|
14
|
-
|
15
|
-
- else
|
16
|
-
%script{src: current_path + '/' + url, defer: 'defer'}
|
7
|
+
%link{rel: 'stylesheet', type: 'text/css', href: '/design/style.css'}
|
8
|
+
- body[:stylesheets].each do |url|
|
9
|
+
- url = current_path + '/' + url unless url.start_with?('/')
|
10
|
+
%link{rel: 'stylesheet', type: 'text/css', href: url}
|
11
|
+
%script{type: 'module', src: '/design/nav.js'}
|
12
|
+
- body[:scripts].each do |script|
|
13
|
+
- script[:src] = current_path + '/' + script[:src] unless script[:src].start_with?('/')
|
14
|
+
%script{script}
|
17
15
|
%body
|
18
16
|
%header
|
19
|
-
%a{id: 'openmenu'
|
17
|
+
%a{id: 'openmenu'}= '☰'
|
20
18
|
%h1
|
21
19
|
%a{href: '/index.html', title: I18n.t('nav.back.home')}= Socket.gethostname.capitalize
|
22
20
|
%nav
|
23
|
-
%a{id: 'closemenu'
|
21
|
+
%a{id: 'closemenu'}= '×'
|
24
22
|
%ul
|
25
23
|
- responders.children_nodes.each do |path, node|
|
26
24
|
- if node.children?
|
@@ -48,7 +46,7 @@
|
|
48
46
|
= ' ' + I18n.t('nav.generated.on_date') + ' ' + Time.now.strftime(I18n.t('date_format'))
|
49
47
|
= ' ' + I18n.t('date_time_separator') + Time.now.strftime(I18n.t('time_format'))
|
50
48
|
%br
|
51
|
-
%a{
|
49
|
+
%a{id: 'openmodal'}= I18n.t('nav.about')
|
52
50
|
%aside#modal
|
53
51
|
%div#modal-content
|
54
52
|
%h2= 'Intranet'
|
@@ -4,23 +4,13 @@
|
|
4
4
|
* and for the modal box.
|
5
5
|
*/
|
6
6
|
|
7
|
+
const openMenu = document.getElementById('openmenu');
|
8
|
+
const closeMenu = document.getElementById('closemenu');
|
9
|
+
const navMenu = document.querySelectorAll('header nav')[0];
|
10
|
+
openMenu.addEventListener('click', function() { navMenu.style.width = 'auto'; });
|
11
|
+
closeMenu.addEventListener('click', function() { navMenu.style.width = ''; });
|
7
12
|
|
8
|
-
|
9
|
-
|
10
|
-
}
|
11
|
-
|
12
|
-
function closeNavMenu() {
|
13
|
-
/* Remove value property set in openNavMenu() */
|
14
|
-
document.querySelectorAll('header nav')[0].style.width = '';
|
15
|
-
}
|
16
|
-
|
17
|
-
function openModal() {
|
18
|
-
document.getElementById('modal').style.display = 'block';
|
19
|
-
}
|
20
|
-
|
21
|
-
window.onclick = function(event) {
|
22
|
-
if (event.target == document.getElementById('modal')) {
|
23
|
-
document.getElementById('modal').style.display = 'none';
|
24
|
-
}
|
25
|
-
}
|
26
|
-
|
13
|
+
const openModal = document.getElementById('openmodal');
|
14
|
+
const modal = document.getElementById('modal');
|
15
|
+
openModal.addEventListener('click', function() { modal.style.display = 'block'; });
|
16
|
+
modal.addEventListener('click', function() { modal.style.display = 'none'; });
|
data/spec/intranet/core_spec.rb
CHANGED
@@ -244,13 +244,21 @@ RSpec.describe Intranet::Core do
|
|
244
244
|
it 'should be called to retrieve the body of the page' do
|
245
245
|
@intranet = described_class.new(Intranet::Logger.new(Intranet::Logger::FATAL))
|
246
246
|
|
247
|
-
responder = Intranet::TestResponder.new(
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
247
|
+
responder = Intranet::TestResponder.new({
|
248
|
+
'/index.html' => [
|
249
|
+
206,
|
250
|
+
'text/html',
|
251
|
+
{
|
252
|
+
content: 'PARTIAL_CONTENT',
|
253
|
+
title: 'MyTitle',
|
254
|
+
stylesheets: ['/resp.css', 'nav.css'],
|
255
|
+
scripts: [
|
256
|
+
{ src: 'module.js', type: 'module' },
|
257
|
+
{ src: '/js/interactive.js', defer: 'defer' }
|
258
|
+
]
|
259
|
+
}
|
260
|
+
]
|
261
|
+
})
|
254
262
|
@intranet.register_module(responder, ['r'], responder.resources_dir)
|
255
263
|
|
256
264
|
thread = Thread.new { @intranet.start }
|
@@ -280,11 +288,11 @@ RSpec.describe Intranet::Core do
|
|
280
288
|
expect(html).to match(%r{<footer>.*#{hostname}.*</footer>}m)
|
281
289
|
|
282
290
|
# Returned HTML document: includes all CSS dependencies, relative or absolute path
|
283
|
-
expect(html).to match(%r{<link href='/
|
291
|
+
expect(html).to match(%r{<link href='/resp.css' rel='stylesheet' type='text/css'})
|
284
292
|
expect(html).to match(%r{<link href='/r/nav.css' rel='stylesheet' type='text/css'})
|
285
293
|
|
286
294
|
# Returned HTML document: includes all JS dependencies
|
287
|
-
expect(html).to match(%r{<script
|
295
|
+
expect(html).to match(%r{<script src='/r/module.js' type='module'></script>})
|
288
296
|
expect(html).to match(%r{<script defer='defer' src='/js/interactive.js'></script>})
|
289
297
|
|
290
298
|
# Returned HTML document: includes Intranet Core name, version and URL
|
@@ -306,7 +314,7 @@ RSpec.describe Intranet::Core do
|
|
306
314
|
responder = Intranet::TestResponder.new(
|
307
315
|
'/index.html' => [206, 'text/html', { content: 'PARTIAL_CONTENT', title: 'MyTitle' }]
|
308
316
|
)
|
309
|
-
other_responder = Intranet::TestResponder.new({},
|
317
|
+
other_responder = Intranet::TestResponder.new({}, true)
|
310
318
|
@intranet.register_module(responder, %w[r], responder.resources_dir)
|
311
319
|
@intranet.register_module(responder, %w[dep_th1], responder.resources_dir)
|
312
320
|
@intranet.register_module(responder, %w[depth2 res_p1], responder.resources_dir)
|
@@ -6,10 +6,8 @@ module Intranet
|
|
6
6
|
class TestResponder < AbstractResponder
|
7
7
|
attr_reader :finalized
|
8
8
|
|
9
|
-
def initialize(responses = {},
|
9
|
+
def initialize(responses = {}, hide_from_menu = false)
|
10
10
|
@responses = responses
|
11
|
-
@extra_css = extra_css
|
12
|
-
@extra_js = extra_js
|
13
11
|
@finalized = false
|
14
12
|
@hide_from_menu = hide_from_menu
|
15
13
|
end
|
@@ -47,14 +45,6 @@ module Intranet
|
|
47
45
|
super(path, query)
|
48
46
|
end
|
49
47
|
|
50
|
-
def css_dependencies
|
51
|
-
super + @extra_css
|
52
|
-
end
|
53
|
-
|
54
|
-
def js_dependencies
|
55
|
-
super + @extra_js
|
56
|
-
end
|
57
|
-
|
58
48
|
private
|
59
49
|
|
60
50
|
def dump_with_encoding(path, query)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intranet-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ebling Mis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml
|
@@ -211,8 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
211
|
- !ruby/object:Gem::Version
|
212
212
|
version: '0'
|
213
213
|
requirements: []
|
214
|
-
|
215
|
-
rubygems_version: 2.7.6.2
|
214
|
+
rubygems_version: 3.2.5
|
216
215
|
signing_key:
|
217
216
|
specification_version: 4
|
218
217
|
summary: Core component to build a custom intranet.
|