Class: Mkmatter::App::Classes::Tags

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/mkmatter/cli/subs/tags.rb

Instance Method Summary collapse

Instance Method Details

#find(type) ⇒ Object

Parameters:

  • type (String)

    Type of content



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mkmatter/cli/subs/tags.rb', line 12

def find(type)
  if Mkmatter::Methods.check_if_jekyll
    table                      = Terminal::Table.new
    table.title                = type.capitalize
    table.style.all_separators = true
    table.headings             = ["#{Paint['Path from Jekyll Root', 'white', :bold]}", "#{Paint['Tags', 'white', :bold]}"]
    
    front_matter = Mkmatter::Methods.find_front_matter(type, 'tags')
    front_matter.each do |path, tags|
      path = path.gsub(/#{Mkmatter::Methods.get_jekyll_root}(\/.*)/, '\1')
      table.add_row([path, "#{tags.join("\n")}"])
    end
    table.align_column(1, :right)
    puts table
  else
    $stderr.puts "#{Paint['Error', :red, :bold]}: Not a Jekyll source directory (no '_config.yml' found in any parent directory)"
  end
end

#genObject

only used for posts



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/mkmatter/cli/subs/tags.rb', line 45

def gen # only used for posts
  if options[:'dry-run']
    if Mkmatter::Tags.has_tag_folder?
      front_matter = Mkmatter::Methods.find_front_matter('post', 'tags')
      tags         = []
      front_matter.each do |key, value|
        tags << value
      end
      all_tags = tags.flatten.sort.uniq
      Mkmatter::Tags.dry_gen all_tags
    else
      $stderr.puts "#{Paint['Error', :red, :bold]}: No tag folder"
    end
  else
    if Mkmatter::Tags.has_tag_folder?
      front_matter = Mkmatter::Methods.find_front_matter('post', 'tags')
      tags         = []
      front_matter.each do |key, value|
        tags << value
      end
      all_tags = tags.flatten.sort.uniq
      Mkmatter::Tags. all_tags
    else
      $stderr.puts "#{Paint['Error', :red, :bold]}: Not a Jekyll source directory (no '_config.yml' found in any parent directory)"
    end
  end
end

#new_tag(tag) ⇒ Object

Parameters:

  • tag (String)

    Tag Name



33
34
35
36
37
38
39
# File 'lib/mkmatter/cli/subs/tags.rb', line 33

def new_tag(tag)
  if Mkmatter::Methods.check_if_jekyll
  
  else
    $stderr.puts "#{Paint['Error', :red, :bold]}: Not a Jekyll source directory (no '_config.yml' found in any parent directory)"
  end
end