Class: Jekyll::WebmentionIO::JSHandler
- Inherits:
-
Object
- Object
- Jekyll::WebmentionIO::JSHandler
- Defined in:
- lib/jekyll/webmention_io/js_handler.rb
Constant Summary collapse
- DEFAULTS =
{ "destination" => "js", "source" => true, "deploy" => true, "uglify" => true, }.freeze
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#resource_name ⇒ Object
readonly
Returns the value of attribute resource_name.
-
#resource_url ⇒ Object
readonly
Returns the value of attribute resource_url.
Instance Method Summary collapse
- #deploy? ⇒ Boolean
- #disabled? ⇒ Boolean
-
#initialize(site) ⇒ JSHandler
constructor
A new instance of JSHandler.
- #render ⇒ Object
- #source? ⇒ Boolean
- #uglify? ⇒ Boolean
Constructor Details
#initialize(site) ⇒ JSHandler
Returns a new instance of JSHandler.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jekyll/webmention_io/js_handler.rb', line 20 def initialize(site) js_config = site.config.dig("webmentions", "js") @disabled = js_config == false js_config = {} unless js_config.is_a?(Hash) js_config = DEFAULTS.merge(js_config) @deploy, @uglify, @source, @destination = js_config.values_at("deploy", "uglify", "source", "destination") @resource_name = "JekyllWebmentionIO.js" @resource_url = File.join( "", site.config["baseurl"].to_s, @destination, @resource_name ) end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
11 12 13 |
# File 'lib/jekyll/webmention_io/js_handler.rb', line 11 def destination @destination end |
#resource_name ⇒ Object (readonly)
Returns the value of attribute resource_name.
11 12 13 |
# File 'lib/jekyll/webmention_io/js_handler.rb', line 11 def resource_name @resource_name end |
#resource_url ⇒ Object (readonly)
Returns the value of attribute resource_url.
11 12 13 |
# File 'lib/jekyll/webmention_io/js_handler.rb', line 11 def resource_url @resource_url end |
Instance Method Details
#deploy? ⇒ Boolean
39 40 41 |
# File 'lib/jekyll/webmention_io/js_handler.rb', line 39 def deploy? @deploy != false end |
#disabled? ⇒ Boolean
35 36 37 |
# File 'lib/jekyll/webmention_io/js_handler.rb', line 35 def disabled? @disabled == true end |
#render ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jekyll/webmention_io/js_handler.rb', line 51 def render if disabled? WebmentionIO.log "info", "JavaScript output is disabled, so the {% webmentions_js %} tag is being skipped" return "" end js_file = deploy? ? "<script src=\"#@resource_url\" async></script>" : "" WebmentionIO.log "info", "Gathering templates for JavaScript." "#{js_file}\n#{WebmentionIO.html_templates}" end |
#source? ⇒ Boolean
47 48 49 |
# File 'lib/jekyll/webmention_io/js_handler.rb', line 47 def source? @source != false end |
#uglify? ⇒ Boolean
43 44 45 |
# File 'lib/jekyll/webmention_io/js_handler.rb', line 43 def uglify? @uglify != false end |