Class Dragonfly::Content
In: lib/dragonfly/content.rb
Parent: Object

A Dragonfly::Content object is responsible for holding

  1. content (in the form of a data string, file, tempfile, or path)
  2. metadata about the content (i.e. name, etc.)

Furthermore, it belongs to a Dragonfly app, so has access to its already registered generators, processors, analysers and datastore. It provides convenience methods for updating its content, and though the original data may have been in the form of a String, or a Pathname, etc. methods like "path", "data" and "file" will always work regardless.

It is acted upon in generator, processor, analyser and datastore methods and provides a standard interface for updating content, no matter how that content first got there (whether in the form of a String/Pathname/File/etc.)

Methods

Included Modules

HasFilename

Attributes

app  [R] 
meta  [RW]  @return [Hash]
previous_temp_objects  [R] 
temp_object  [R] 

Public Class methods

Public Instance methods

Add to the meta (merge) @param meta [Hash] - should be json-like, i.e. contain no types other than String, Number, Boolean

Analyse the content using a pre-registered analyser @example

  content.analyse(:width)  # ===> 280

@example

  "data:image/jpeg;base64,IGSsdhfsoi..."

@return [String] A data url representation of the data

Set the content using a pre-registered generator @example

  content.generate!(:text, "some text")

@return [Content] self

Used by ‘dup’ and ‘clone‘

The mime-type taken from the name‘s file extension @example "image/jpeg" @return [String]

@example "beach.jpg" @return [String]

@example

  content.name = "beach.jpg"

Update the content using a pre-registered processor @example

  content.process!(:convert, "-resize 300x300")

@return [Content] self

Analyse the content using a shell command @param opts [Hash] passing :escape => false doesn‘t shell-escape each word @example

  content.shell_eval do |path|
    "file --mime-type #{path}"
  end
  # ===> "beach.jpg: image/jpeg"

Set the content using a shell command @param opts [Hash] :ext sets the file extension of the new path and :escape => false doesn‘t shell-escape each word @example

  content.shell_generate do |path|
    "/usr/local/bin/generate_text gumfry -o #{path}"
  end

@return [Content] self

Update the content using a shell command @param opts [Hash] :ext sets the file extension of the new path and :escape => false doesn‘t shell-escape each word @example

  content.shell_update do |old_path, new_path|
    "convert -resize 20x10 #{old_path} #{new_path}"
  end

@return [Content] self

Update the content @param obj [String, Pathname, Tempfile, File, Content, TempObject] can be any of these types @param meta [Hash] - should be json-like, i.e. contain no types other than String, Number, Boolean @return [Content] self

[Validate]