Class: Octopress::Ink::Assets::Config

Inherits:
Asset
  • Object
show all
Defined in:
lib/octopress-ink/assets/config.rb

Direct Known Subclasses

LangConfig

Constant Summary

Constants inherited from Asset

Asset::FRONT_MATTER

Instance Attribute Summary

Attributes inherited from Asset

#base, #dir, #exists, #file, #plugin, #replacement, #root

Instance Method Summary collapse

Methods inherited from Asset

#add, #asset_info, #content, #copy, #data, #destination, #disable, #disabled?, #ext, #filename, #is_disabled, #path, #payload, #remove_jekyll_asset, #replaced?

Constructor Details

#initialize(plugin, path) ⇒ Config

Returns a new instance of Config.



6
7
8
9
10
11
12
13
# File 'lib/octopress-ink/assets/config.rb', line 6

def initialize(plugin, path)
  @root = plugin.assets_path
  @plugin = plugin
  @dir = plugin.slug
  @base = ''
  @exists = {}
  @file = path
end

Instance Method Details

Permalinks should not contain file extensions This replaces file extensions in the keys so they still work



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/octopress-ink/assets/config.rb', line 43

def fix_permalinks(config)
  fixed_permalinks = {}
  config['permalinks'] ||= {}

  config['permalinks'].each do |k,v|
    if k.match('.')
      key = k.sub(File.extname(k), '')
      fixed_permalinks[key] = v
      config['permalinks'].delete(k)
    end
  end

  config['permalinks'] = fixed_permalinks
  config
end

#infoObject

If config plugin config file exists, return contents for list command



16
17
18
19
20
21
22
# File 'lib/octopress-ink/assets/config.rb', line 16

def info
  if exists?(config = plugin_path)
    Ink::Utils.pretty_print_yaml(read)
  else
    "   none"
  end
end

#readObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/octopress-ink/assets/config.rb', line 24

def read
  config = {}
  default = plugin_path
  if exists? default
    config = SafeYAML.load_file(default) || {}
  end

  if exists? user_path
    user_config = SafeYAML.load_file(user_path) || {}
    config = Jekyll::Utils.deep_merge_hashes(config, user_config)
  end

  fix_permalinks(config)
end