Class: Mkmatter::Questions::Page
- Inherits:
-
Object
- Object
- Mkmatter::Questions::Page
- Defined in:
- lib/mkmatter/questions.rb
Overview
Instance Attribute Summary collapse
-
#answers ⇒ Object
readonly
Returns the value of attribute answers.
Instance Method Summary collapse
- #ask ⇒ Object
- #get_001_title ⇒ Object
- #get_002_tags ⇒ Array
- #get_003_categories ⇒ Array
- #get_004_time_zone ⇒ String
- #get_005_file_format ⇒ String
- #get_006_extra_fields ⇒ String
Instance Attribute Details
#answers ⇒ Object (readonly)
Returns the value of attribute answers.
133 134 135 |
# File 'lib/mkmatter/questions.rb', line 133 def answers @answers end |
Instance Method Details
#ask ⇒ Object
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_title ⇒ Object
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_tags ⇒ Array
162 163 164 165 166 167 |
# File 'lib/mkmatter/questions.rb', line 162 def hl = @hl hl.ask("Tags? (write one on each line, then type '.') ") do |q| q.gather = '.' end end |
#get_003_categories ⇒ 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_zone ⇒ 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_format ⇒ 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 || .header = 'Choose whether you want HTML or Markdown' .choice 'html' do return 'html' end .choice 'md' do return 'md' end .prompt = '? ' end end |
#get_006_extra_fields ⇒ 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 |