Class: Jekyll::Fridge::ContentDrop

Inherits:
Liquid::Drop
  • Object
show all
Includes:
Enumerable
Defined in:
lib/jekyll-fridge.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, base, query = "", data = nil) ⇒ ContentDrop

Returns a new instance of ContentDrop.



126
127
128
129
130
131
# File 'lib/jekyll-fridge.rb', line 126

def initialize(client, base, query = "", data = nil)
  @client = client
  @base = base
  @query = query
  @data = data
end

Instance Method Details

#before_method(method) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/jekyll-fridge.rb', line 133

def before_method(method)
  # check for single content item
  item = @client.get("#{@base}/#{method}?#{@query}")
  return Model.new(item) if item && item.kind_of?(FridgeApi::Model)

  # filter by content type
  if @base == "content" && @query.empty?
    types = @client.get("#{@base}?type=#{method}")
    return ContentDrop.new(@client, @base, "type=#{method}", types) if types
  end

  # filter by user role
  if @base == "users" && @query.empty?
    roles = @client.get("#{@base}?role=#{method}")
    return ContentDrop.new(@client, @base, "role=#{method}", roles) if roles
  end

  nil
end

#each(&block) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
# File 'lib/jekyll-fridge.rb', line 153

def each &block
  @data ||= @client.get("#{@base}?#{@query}")
  @data.each do |v|
    m = Model.new v
    if block_given?
      block.call m
    else
      yield m
    end
  end
end