Class: Jekyll::FastReader::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/fast_reader/configuration.rb

Constant Summary collapse

DEFAULTS =
{
  "enabled"            => true,
  "collections"        => ["posts"],
  "exclude_selectors"  => %w[code pre script style kbd samp],
  "css_output_path"    => "/assets/fast-reader.css",
  "js_output_path"     => "/assets/fast-reader.js",
  "stop_words_extra"   => [],
  "toggle"             => false,
  "default_on"         => true
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, baseurl = "") ⇒ Configuration

Returns a new instance of Configuration.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jekyll/fast_reader/configuration.rb', line 22

def initialize(config, baseurl = "")
  merged             = DEFAULTS.merge(config)
  @enabled           = merged["enabled"]
  @collections_map   = normalize_collections(merged["collections"])
  @exclude_selectors = Array(merged["exclude_selectors"])
  @css_output_path   = merged["css_output_path"]
  @js_output_path    = merged["js_output_path"]
  @stop_words_extra  = Array(merged["stop_words_extra"]).map(&:to_s)
  @toggle            = merged["toggle"]
  @default_on        = merged["default_on"]
  @baseurl           = baseurl
  freeze
end

Instance Attribute Details

#baseurlObject (readonly)

Returns the value of attribute baseurl.



15
16
17
# File 'lib/jekyll/fast_reader/configuration.rb', line 15

def baseurl
  @baseurl
end

#css_output_pathObject (readonly)

Returns the value of attribute css_output_path.



15
16
17
# File 'lib/jekyll/fast_reader/configuration.rb', line 15

def css_output_path
  @css_output_path
end

#default_onObject (readonly)

Returns the value of attribute default_on.



15
16
17
# File 'lib/jekyll/fast_reader/configuration.rb', line 15

def default_on
  @default_on
end

#exclude_selectorsObject (readonly)

Returns the value of attribute exclude_selectors.



15
16
17
# File 'lib/jekyll/fast_reader/configuration.rb', line 15

def exclude_selectors
  @exclude_selectors
end

#js_output_pathObject (readonly)

Returns the value of attribute js_output_path.



15
16
17
# File 'lib/jekyll/fast_reader/configuration.rb', line 15

def js_output_path
  @js_output_path
end

#stop_words_extraObject (readonly)

Returns the value of attribute stop_words_extra.



15
16
17
# File 'lib/jekyll/fast_reader/configuration.rb', line 15

def stop_words_extra
  @stop_words_extra
end

#toggleObject (readonly)

Returns the value of attribute toggle.



15
16
17
# File 'lib/jekyll/fast_reader/configuration.rb', line 15

def toggle
  @toggle
end

Class Method Details

.from(site) ⇒ Object



18
19
20
# File 'lib/jekyll/fast_reader/configuration.rb', line 18

def self.from(site)
  new(site.config["fast_reader"] || {}, site.config["baseurl"].to_s.chomp("/"))
end

Instance Method Details

#collection_enabled?(label) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/jekyll/fast_reader/configuration.rb', line 40

def collection_enabled?(label)
  return false unless @collections_map.key?(label)

  @collections_map[label] != false
end

#enabled?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/jekyll/fast_reader/configuration.rb', line 36

def enabled?
  @enabled
end

#stop_words_for(label) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/jekyll/fast_reader/configuration.rb', line 46

def stop_words_for(label)
  options = @collections_map[label]
  return @stop_words_extra unless options.is_a?(Hash)

  per_collection = Array(options["stop_words_extra"]).map(&:to_s)
  per_collection + @stop_words_extra
end