Module: Roda::RodaPlugins::BridgetownRoutes::InstanceMethods

Defined in:
lib/roda/plugins/bridgetown_routes.rb

Instance Method Summary collapse

Instance Method Details

#renderObject



63
64
65
# File 'lib/roda/plugins/bridgetown_routes.rb', line 63

def render(...)
  view.render(...)
end

#render_with(data: {}) ⇒ Object

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



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
# File 'lib/roda/plugins/bridgetown_routes.rb', line 35

def render_with(data: {}) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  path = Kernel.caller_locations(1, 1).first.path
  source_path = Pathname.new(path).relative_path_from(
    bridgetown_site.in_source_dir("_routes")
  )
  code = response._route_file_code

  unless code.present?
    raise Bridgetown::Errors::FatalException,
          "`render_with' method must be called from a template-based file in `src/_routes'"
  end

  data = Bridgetown::Model::BuilderOrigin.new(
    Bridgetown::Model::BuilderOrigin.id_for_builder_path(
      self, Addressable::URI.encode(source_path.to_s)
    )
  ).read do
    data[:_collection_] = bridgetown_site.collections.pages
    data[:_relative_path_] = source_path
    data[:_content_] = code
    data
  end

  Bridgetown::Model::Base.new(data).to_resource.tap do |resource|
    resource.roda_app = self
  end.read!.transform!.output
end

#view(view_class: Bridgetown::ERBView) ⇒ Object



67
68
69
70
71
# File 'lib/roda/plugins/bridgetown_routes.rb', line 67

def view(view_class: Bridgetown::ERBView)
  response._fake_resource_view(
    view_class: view_class, roda_app: self, bridgetown_site: bridgetown_site
  )
end