Class: JekyllThemeGuidesMbland::NavigationMenuWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-theme-guides-mbland/navigation.rb

Constant Summary collapse

YAML_PREFIX =
"---\n".freeze

Class Method Summary collapse

Class Method Details

.format_navigation_section(nav_data) ⇒ Object


272
273
274
# File 'lib/jekyll-theme-guides-mbland/navigation.rb', line 272

def self.format_navigation_section(nav_data)
  nav_data.empty? ? '' : nav_data.to_yaml[YAML_PREFIX.size..-1]
end

.process_line(line, lines, nav_data, in_navigation = false) ⇒ Object


257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/jekyll-theme-guides-mbland/navigation.rb', line 257

def self.process_line(line, lines, nav_data, in_navigation = false)
  if !in_navigation && line.start_with?('navigation:')
    lines << line << format_navigation_section(nav_data)
    in_navigation = true
  elsif in_navigation
    in_navigation = line.start_with?(' ', '-')
    lines << line unless in_navigation
  else
    lines << line
  end
  in_navigation
end

.write_navigation_data_to_config_file(config_path, nav_data) ⇒ Object


248
249
250
251
252
253
254
255
# File 'lib/jekyll-theme-guides-mbland/navigation.rb', line 248

def self.write_navigation_data_to_config_file(config_path, nav_data)
  lines = []
  in_navigation = false
  File.open(config_path).each_line do |line|
    in_navigation = process_line line, lines, nav_data, in_navigation
  end
  File.write config_path, lines.join
end