lib/intranet/pictures/responder.rb in intranet-pictures-1.0.6 vs lib/intranet/pictures/responder.rb in intranet-pictures-1.1.0

- old
+ new

@@ -85,36 +85,21 @@ case path when %r{^/index\.html$} then serve_home when %r{^/browse_\w+\.html$} serve_groups(path.gsub(%r{^/browse_(\w+)\.html$}, '\\1'), query) when %r{^/api/} then serve_api(path.gsub(%r{^/api}, ''), query) + when %r{^/i18n\.js$} then serve_i18n_js else super(path, query) end end # The title of the Pictures module, as displayed on the web page. # @return [String] The title of the Pictures module web page. def title @provider.title end - # Provides the list of Cascade Style Sheets (CSS) dependencies for this module. - # @return [Array<String>] The list of CSS dependencies. - def css_dependencies - super + ['design/style.css', - 'design/photoswipe/photoswipe.css', - 'design/photoswipe/default-skin/default-skin.css'] - end - - # Provides the list of Javascript files (JS) dependencies for this module. - # @return [Array<String>] The list of JS dependencies. - def js_dependencies - super + ['design/jpictures.js', - 'design/photoswipe/photoswipe.min.js', - 'design/photoswipe/photoswipe-ui-default.min.js'] - end - private # Extract a selector from the given +query+. # @return [Hash<String,String>] The picture or group selector. def selector(query) @@ -139,10 +124,23 @@ return true if query['sort_order'].nil? || query['sort_order'] == 'asc' raise KeyError # incorrect value for 'sort_order' end + # Provides the list of required stylesheets. + # @return [Array<String>] The list of required stylesheets. + def stylesheets + ['design/style.css', 'design/photoswipe/photoswipe.css', + 'design/photoswipe/photoswipe-dynamic-caption-plugin.css'] + end + + # Provides the list of required script files. + # @return [Array<Hash<Symbol,String>>] The list of required scripts. + def scripts + [{ src: 'design/jpictures.js', type: 'module' }] + end + ########################################################################## ### Servicing of the HTML "display-able" content ### ########################################################################## def active_filters(query) @@ -193,21 +191,32 @@ filters.map { |k, v| [k, v].join('=') }.join('&') end def serve_home content = to_markup('pictures_home', nav: make_nav) - [206, 'text/html', { content: content, title: title }] + [206, 'text/html', + { content: content, title: title, stylesheets: stylesheets, scripts: scripts }] rescue KeyError [404, '', ''] end def serve_groups(type, query) groups = @provider.list_groups(type, selector(query), sort_by(query), sort_order(query)) content = to_markup('pictures_browse', nav: make_nav(type, query), group_type: type, filters: selector(query), groups: groups) - [206, 'text/html', { content: content, title: title }] + [206, 'text/html', + { content: content, title: title, stylesheets: stylesheets, scripts: scripts }] rescue KeyError [404, '', ''] + end + + def serve_i18n_js + [200, 'text/javascript', + "export default {\n" \ + " viewer_close: '#{I18n.t('pictures.viewer.close')}',\n" \ + " viewer_zoom: '#{I18n.t('pictures.viewer.zoom')}',\n" \ + " viewer_previous: '#{I18n.t('pictures.viewer.previous')}',\n" \ + " viewer_next: '#{I18n.t('pictures.viewer.next')}' };"] end ########################################################################## ### Servicing of the REST API (raw JSON data & pictures) ### ##########################################################################