Sha256: d0a514b5b4702ed5df188bfff9d7ca6a2613f9f5d479b69f66338e29590fb74c

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

require 'net/http'
require 'uri'
require 'ri_cal'

module Almanack
  class Configuration
    class ThemeNotFound < StandardError; end

    DEFAULT_THEME = "legacy"
    DEFAULT_DAYS_LOOKAHEAD = 30

    attr_reader :event_sources
    attr_accessor :title, :theme, :theme_paths, :theme_root, :days_lookahead

    def initialize
      reset!
    end

    def reset!
      @theme = DEFAULT_THEME
      @days_lookahead = DEFAULT_DAYS_LOOKAHEAD
      @event_sources = []

      @theme_paths = [
        Pathname.pwd.join('themes'),
        Pathname(__dir__).join('themes')
      ]
    end

    def theme_root
      paths = theme_paths.map { |path| path.join(theme) }
      root = paths.find { |path| path.exist? }
      root || raise(ThemeNotFound, "Could not find theme #{theme} in #{paths}")
    end

    def add_ical_feed(url)
      @event_sources << EventSource::IcalFeed.new(url)
    end

    def add_events(events)
      @event_sources << EventSource::Static.new(events)
    end

    def add_meetup_group(options)
      @event_sources << EventSource::MeetupGroup.new(options)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
almanack-1.0.3 lib/almanack/configuration.rb
almanack-1.0.2 lib/almanack/configuration.rb
almanack-1.0.1 lib/almanack/configuration.rb