Class: Pakyow::Plugin::State Private

Inherits:
Object
  • Object
show all
Defined in:
lib/pakyow/plugin/state.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(plugin, path: plugin.class.plugin_path) ⇒ State

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of State.



9
10
11
# File 'lib/pakyow/plugin/state.rb', line 9

def initialize(plugin, path: plugin.class.plugin_path)
  @plugin, @path = plugin, path
end

Instance Method Details

#backend_path(aspect) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
# File 'lib/pakyow/plugin/state.rb', line 13

def backend_path(aspect)
  File.join(@path, "backend", aspect.to_s)
end

#frontend_pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
# File 'lib/pakyow/plugin/state.rb', line 17

def frontend_path
  File.join(@path, "frontend")
end

#load_frontendObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/pakyow/plugin/state.rb', line 21

def load_frontend
  @plugin.state(:templates) << Presenter::Templates.new(
    @plugin.config.name,
    frontend_path,
    config: {
      prefix: @plugin.class.mount_path
    },
    processor: Presenter::ProcessorCaller.new(
      @plugin.parent.state(:processor).map { |processor|
        processor.new(@plugin.parent)
      }
    )
  ).tap do |plugin_templates|
    if app_templates = @plugin.parent.state(:templates).find { |templates| templates.name == :default }
      plugin_templates.paths.each do |path|
        plugin_info = plugin_templates.info(path)

        # Use the app's layout, if available.
        #
        if app_templates.layouts.include?(plugin_info[:page].info(:layout))
          plugin_info[:layout] = app_templates.layout(plugin_info[:page].info(:layout).to_sym)
          plugin_info[:partials].merge!(app_templates.includes)
        end

        if app_info = app_templates.info(path)
          # Define the plugin view as the `plug` partial so that it can be included.
          #
          plugin_info[:partials][:plug] = Presenter::Views::Partial.from_object(
            :plug, plugin_info[:page].object
          )

          # Set the layout for the page.
          #
          plugin_info[:layout] = app_templates.layout(app_info[:page].info(:layout).to_sym)

          # Include the app partials, since we're using a page from the app that might include them.
          #
          plugin_info[:partials].merge!(app_info[:partials])

          # Finally, override the page with the one from the app.
          #
          plugin_info[:page] = app_info[:page]
        end
      end
    end
  end
end