Method: Roda::RodaPlugins::BridgetownRoutes::InstanceMethods#render_with
- Defined in:
- lib/roda/plugins/bridgetown_routes.rb
#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 |