Sha256: 57db3e8cdb273eea09590fac84bd19aa915c130316244831cc18476a36626c17

Contents?: true

Size: 934 Bytes

Versions: 7

Compression:

Stored size: 934 Bytes

Contents

# encoding: UTF-8

module Spontaneous::Plugins
  module Media
    extend ActiveSupport::Concern

    # InstanceMethods

    def media_filepath(*args)
      File.join(Spontaneous.media_dir, padded_id, padded_revision, *args)
    end

    def media_urlpath(*args)
      File.join("/media", padded_id, padded_revision, *args)
    end

    def padded_id
      save if media_id.nil?
      media_id.to_s.rjust(5, "0")
    end

    def media_id
      id
    end

    def padded_revision
      Spontaneous::Site.working_revision.to_s.rjust(4, "0")
    end

    # TODO: Is this still used? It shouldn't be
    def make_media_file(src_file, filename = nil)
      filename ||= File.basename(src_file)
      filename = Spontaneous::Media.to_filename(filename)
      media_filepath = media_filepath(filename)
      FileUtils.mkdir_p(File.dirname(media_filepath))
      FileUtils.cp(src_file, media_filepath)
      media_filepath
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
spontaneous-0.2.0.alpha7 lib/spontaneous/plugins/media.rb
spontaneous-0.2.0.alpha6 lib/spontaneous/plugins/media.rb
spontaneous-0.2.0.alpha5 lib/spontaneous/plugins/media.rb
spontaneous-0.2.0.alpha4 lib/spontaneous/plugins/media.rb
spontaneous-0.2.0.alpha3 lib/spontaneous/plugins/media.rb
spontaneous-0.2.0.alpha2 lib/spontaneous/plugins/media.rb
spontaneous-0.2.0.alpha1 lib/spontaneous/plugins/media.rb