Class: Jekyll::Meetup::Command

Inherits:
Command
  • Object
show all
Defined in:
lib/jekyll/meetup/command.rb

Overview

Add the ‘jekyll meetup` command which downloads from Meetup.

Class Method Summary collapse

Class Method Details

.init_with_program(prog) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jekyll/meetup/command.rb', line 14

def init_with_program(prog)
  prog.command(:meetup) do |c|
    c.syntax 'meetup download'
    c.description 'Downloads events from meetup'
    c.action do |args, options|
      config = configuration_from_options(options)
      validate_command!(args, options, config)
      case args[0]
      when 'download'
        process_download(config)
      end
    end
  end
end

.process_download(config) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/jekyll/meetup/command.rb', line 41

def process_download(config)
  collection = DataCollection.new(
    config['data_dir'],
    config['meetup']['collection_name']
  )
  collection.remove_existing_files!

  Meetup::ApiClient
    .events(config['meetup']['urlname'])
    .each_with_index do |event, i|
    filename = format(
      '%<date>s-%<name>s.yml',
      name: filenamify(event['name']),
      date: event['local_date']
    )

    collection.create_file(filename) { |f| f.puts YAML.dump(event) }
    collection.create_symlink(filename, 'upcoming.yml') if i.zero?
  end
end

.validate_command!(args, options, config) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jekyll/meetup/command.rb', line 29

def validate_command!(args, options, config)
  # future-proof against other options like OAuth setup:
  raise '`jekyll meetup` must be called with the download argument' \
    unless args[0] == 'download'

  # ensure required config is there:
  raise 'No meetup.urlname found in config file.' \
    unless config['meetup']['urlname']
  raise 'No meetup.colleciton_name found in config file.' \
    unless config['meetup']['collection_name']
end