Class: Mkmatter::Questions::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/mkmatter/questions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#answersObject (readonly)

Returns the value of attribute answers.



16
17
18
# File 'lib/mkmatter/questions.rb', line 16

def answers
  @answers
end

Instance Method Details

#askObject



19
20
21
22
23
24
25
26
# File 'lib/mkmatter/questions.rb', line 19

def ask
  known_questions = methods.sort.delete_if { |m| m.to_s !~ /^get_.*$/ }
  known_questions.each do |m|
    @answers[:layout] = 'post'
    @answers[m.to_s.gsub(/^get_[0-9]{3}_/, '')] = method(m).call
  end
  @answers
end

#get_001_titleObject



34
35
36
37
38
39
40
41
42
# File 'lib/mkmatter/questions.rb', line 34

def get_001_title
  hl = @hl
  title = hl.ask 'Title: '
  if hl.agree("Would you like it 'titleized' (Title instead of title)? ")
    title.titleize
  else
    title
  end
end

#get_002_tagsArray

Returns:

  • (Array)


45
46
47
48
49
50
# File 'lib/mkmatter/questions.rb', line 45

def get_002_tags
  hl = @hl
  hl.ask("Tags? (write one on each line, then type '.') ") do |q|
    q.gather = '.'
  end
end

#get_003_categoriesArray

Returns:

  • (Array)


53
54
55
56
57
58
# File 'lib/mkmatter/questions.rb', line 53

def get_003_categories
  hl = @hl
  hl.ask("Categories? (write one on each line, then type '.') ") do |q|
    q.gather = '.'
  end
end

#get_004_time_zoneString

Returns:

  • (String)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/mkmatter/questions.rb', line 61

def get_004_time_zone
  hl = @hl
  custom = nil
  timezone = hl.choose do |m|
    m.header = 'Time Zone? (select by number)'
    m.choice('Eastern Time (US & Canada)') do
      return 'Eastern Time (US & Canada)'
    end
    m.choice('Central Time (US & Canada)') do
      return 'Central Time (US & Canada)'
    end
    m.choice :neither
    m.prompt = '? '
  end
  custom = hl.ask('Other Time Zone: ', String) if timezone == :neither
  return unless custom

  hl.say('Checking TimeZone Validity')
  print '.'
  sleep(0.05)
  5.times do
    print '.'
    sleep(0.05)
    puts ''
    TimeZone.find_tzinfo custom
  end
  custom
end

#get_005_file_formatString

Returns:

  • (String)


91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/mkmatter/questions.rb', line 91

def get_005_file_format
  hl = @hl
  hl.choose do |menu|
    menu.header = 'Choose whether you want HTML or Markdown'
    menu.choice 'html' do
      return 'html'
    end
    menu.choice 'md' do
      return 'md'
    end
    menu.prompt = '? '
  end
end

#get_006_extra_fieldsString

Returns:

  • (String)


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/mkmatter/questions.rb', line 105

def get_006_extra_fields
  hl = @hl
  custom_fields = nil
  if hl.agree('Do you want to add custom fields? (usable as {{LAYOUT_TYPE.FIELD}} in templates) ', true)
    hl.say('Your fields should be inputted as FIELD=>TEXT HERE')
    hl.say("Type 'EOL' on a new line then press Enter when you are done.")
    hl.say("<% color('NOTE', :bold, :red) %>: Input is <% color('NOT', :bold, :red) %> evaluated!")
    custom_fields = hl.ask('Fields?') do |q|
      q.gather = /^EOL$/
    end
  end
  if custom_fields
    fields = Hash.new
    custom_fields.each do |field|
      field = field.split(/=>/)
      fields.store(field[0].to_s, field[1])
    end
    
  elsif custom_fields.nil?
    hl.say('No extra fields were added.')
    return
  else
  end
  custom_fields
end