Sha256: f2e855753cf0f7d8a754e4de8a8e9d56fcfbd593cf908a2333d35cd50e830edd

Contents?: true

Size: 1.98 KB

Versions: 25

Compression:

Stored size: 1.98 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    module Calendar
      # This class serves as a base class to render calendars. Please, inherit
      # from it and overwrite the `events` with whatever logic you need to do
      # it. After that, modify the `Decidim::Meetings::Calendar.for` method to
      # include your new class.
      class BaseCalendar
        # Convenience method to shorten the calls. Converts the resource
        # meetings to the ICalendar format.
        #
        # resource - a resource that has meetings.
        #
        # Returns a String.
        def self.for(resource, filters = nil)
          new(resource, filters).calendar
        end

        # Initializes the class.
        #
        # resource - a resource that has meetings.
        def initialize(resource, filters = nil)
          @resource = resource
          @filters = filters
        end

        # Converts the resource meetings to the ICalendar format.
        #
        # Returns a String.
        def calendar
          return if events.blank?

          <<~CALENDAR.gsub("\n\n", "\n")
            BEGIN:VCALENDAR\r
            VERSION:2.0\r
            PRODID:icalendar-ruby\r
            CALSCALE:GREGORIAN\r
            #{events}
            END:VCALENDAR\r
          CALENDAR
        end

        # Internal: this method is supposed to be overwritten by classes
        # inheriting from this one. It should find the relevant meetings that
        # will be exported, and convert them to ICalendar events. Please use the
        # `MeetingToEvent` class to do so. Since this method returns a String,
        # you can cache its contents. Check existing implementations for an
        # example of how to achieve it.
        #
        # Returns a String.
        def events
          raise "Please, overwrite this method. You can use the `MeetingToEvent` class to convert a meeting to the correct ICalendar format."
        end

        private

        attr_reader :resource
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-meetings-0.29.1 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.28.4 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.27.9 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.29.0 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.28.3 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.27.8 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.29.0.rc4 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.29.0.rc3 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.29.0.rc2 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.29.0.rc1 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.28.2 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.27.7 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.28.1 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.27.6 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.28.0 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.27.5 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.28.0.rc5 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.28.0.rc4 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.27.4 app/services/decidim/meetings/calendar/base_calendar.rb
decidim-meetings-0.27.3 app/services/decidim/meetings/calendar/base_calendar.rb