Class: Jekyll::ActionNetwork::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/action-network/action.rb

Overview

An action network action, call the doc method to get a Jekyll::Document for this action

Instance Method Summary collapse

Constructor Details

#initialize(site, name, collection, config, action, settings) ⇒ Action

Returns a new instance of Action.



9
10
11
12
13
14
15
16
17
# File 'lib/jekyll/action-network/action.rb', line 9

def initialize(site, name, collection, config, action, settings)
  @site = site
  @collection = collection
  @config = config
  @action = action
  @name = name
  @settings = settings
  @utils = Jekyll::ActionNetwork::Utils.new
end

Instance Method Details

#blindpostObject



56
57
58
59
# File 'lib/jekyll/action-network/action.rb', line 56

def blindpost
  linked_type = @settings['endpoint_mappings'][@name]
  return @action['_links']["osdi:#{linked_type}"]['href'] if linked_type
end

#contentObject



61
62
63
# File 'lib/jekyll/action-network/action.rb', line 61

def content
  @content ||= @action[@config["content"]]
end

#docObject



19
20
21
22
23
24
25
26
# File 'lib/jekyll/action-network/action.rb', line 19

def doc
  return @doc if @doc

  @doc = Jekyll::Document.new(path, collection: @collection, site: @site)
  @doc.content = content
  @doc.merge_data!(front_matter)
  @doc
end

#endpointObject



52
53
54
# File 'lib/jekyll/action-network/action.rb', line 52

def endpoint
  @action['_links']['self']['href']
end

#front_matterObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jekyll/action-network/action.rb', line 36

def front_matter
  return @front_matter if @front_matter

  @front_matter = {}
  @config["mappings"].each do |a, d|
    front_matter[d] = @action[a]
  end
  @front_matter["layout"] = @config["layout"]
  @front_matter["slug"] = slug
  @front_matter["embed_code"] = @utils.make_embed_code(@action["browser_url"])
  @front_matter["action_type"] = @name
  @front_matter["action_network_endpoint"] = endpoint
  @front_matter["action_network_blindpost"] = blindpost
  @front_matter
end

#pathObject



32
33
34
# File 'lib/jekyll/action-network/action.rb', line 32

def path
  @path ||= File.join(@site.source, "_#{@config["collection"]}", "#{slug}.md")
end

#slugObject



28
29
30
# File 'lib/jekyll/action-network/action.rb', line 28

def slug
  @slug ||= @action["browser_url"].split("/")[-1] if @action["browser_url"]
end