Class: Mkmatter::Questions::Page

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

Overview

Returns:

  • (OpenStruct)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#answersObject (readonly)

Returns the value of attribute answers.



133
134
135
# File 'lib/mkmatter/questions.rb', line 133

def answers
  @answers
end

Instance Method Details

#askObject



136
137
138
139
140
141
142
143
# File 'lib/mkmatter/questions.rb', line 136

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

#get_001_titleObject



151
152
153
154
155
156
157
158
159
# File 'lib/mkmatter/questions.rb', line 151

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)


162
163
164
165
166
167
# File 'lib/mkmatter/questions.rb', line 162

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)


170
171
172
173
174
175
# File 'lib/mkmatter/questions.rb', line 170

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)


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/mkmatter/questions.rb', line 178

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)


208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/mkmatter/questions.rb', line 208

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)


222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/mkmatter/questions.rb', line 222

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("<% HighLine.color('NOTE', :bold, :red) %>: Input is <% HighLine.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
    self.extra_fields = fields
  elsif custom_fields.nil?
    hl.say('No extra fields were added.')
    return
  else
  end
  custom_fields
end