Class: Jekyll::SvgViewer::AssetManager
- Inherits:
-
Object
- Object
- Jekyll::SvgViewer::AssetManager
- Defined in:
- lib/jekyll/svg_viewer/asset_manager.rb
Constant Summary collapse
- ASSET_ROOT =
File.("../../../assets/svg-viewer", __dir__)
- OUTPUT_DIR =
"assets/svg-viewer"
Class Method Summary collapse
- .copy_assets(site) ⇒ Object
- .flag_page_for_assets(site, page) ⇒ Object
- .hooks_registered? ⇒ Boolean
- .locale_payload(_site) ⇒ Object
- .register(_site) ⇒ Object
Class Method Details
.copy_assets(site) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/jekyll/svg_viewer/asset_manager.rb', line 39 def copy_assets(site) destination = File.join(site.dest, OUTPUT_DIR) FileUtils.mkdir_p(destination) Dir.glob(File.join(ASSET_ROOT, "**", "*")).each do |path| next if File.directory?(path) relative = path.delete_prefix("#{ASSET_ROOT}/") target = File.join(destination, relative) FileUtils.mkdir_p(File.dirname(target)) FileUtils.cp(path, target) end end |
.flag_page_for_assets(site, page) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/jekyll/svg_viewer/asset_manager.rb', line 30 def flag_page_for_assets(site, page) runtime = site.config["svg_viewer_runtime"] ||= {} runtime["required_paths"] ||= Set.new mark_page_hash!(page) path = extract_path(page) runtime["required_paths"] << path if path end |
.hooks_registered? ⇒ Boolean
12 13 14 |
# File 'lib/jekyll/svg_viewer/asset_manager.rb', line 12 def hooks_registered? @hooks_registered ||= false end |
.locale_payload(_site) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/jekyll/svg_viewer/asset_manager.rb', line 52 def locale_payload(_site) locales_path = File.join(ASSET_ROOT, "i18n", "locales.json") return {} unless File.exist?(locales_path) JSON.parse(File.read(locales_path)) rescue JSON::ParserError {} end |
.register(_site) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jekyll/svg_viewer/asset_manager.rb', line 16 def register(_site) return if hooks_registered? @hooks_registered = true Jekyll::Hooks.register [:pages, :documents], :post_render do |doc| (doc) end Jekyll::Hooks.register :site, :post_write do |s| copy_assets(s) end end |