lib/sinatra/export.rb
def export! paths: nil, skips: [], filters: [], use_routes: nil, error_handler: nil,  &block
        @builder ||= 
          if self.builder
            self.builder
          else
            Builder.new(self, paths: paths, skips: skips, filters: filters, use_routes: use_routes, error_handler: error_handler )
          end
        @builder.build! &block
      end
# The entry method. Run this to export the app to files.
# @example
#   # The default: Will use the paths from Sinatra Namespace
#   app.export!
#
#   # Skip a path (or paths)
#   app.export! skips: ["/admin"]
#
#   # Only visit the homepage and the site map
#   app.export! paths: ["/", "/site-map"]
#
#   # Visit the 404 error page by supplying the expected
#   # status code (so as not to trigger an error)
#   app.export! paths: ["/", ["/404.html",404]]
#
#   # Filter out mentions of localhost:4567
#   filter = ->(content){ content.gsub("localhost:4567, "example.org") }
#   app.export! filters: [filter]
#
#   # Use routes found by Sinatra AdvancedRoutes *and*
#   # ones supplied via `paths`
#   app.export! paths: ["/crazy/deep/page/path"], use_routes: true
#
#   # Supply a path and scan the output for an internal link
#   # adding it to the list of paths to be visited
#   app.export! paths: "/" do |builder|
#     if builder.last_response.body.include? "/echo-1"
#       builder.paths << "/echo-1"
#     end
#   end
#
# @param [Array<String>,Array<URI>] paths Paths that will be requested by the exporter.
# @param [Array<String>] skips: Paths that will be ignored by the exporter.
# @param [TrueClass] use_routes Whether to use Sinatra AdvancedRoutes to look for paths to send to the builder.
# @param [Array<#call>] filters Filters will be applied to every file as it is written in the order given.
# @param [#call] error_handler Define your own error handling. Takes one argument, a description of the error.
# @yield [builder] Gives a Builder instance to the block (see Builder) that is called for every path visited.
# @note By default the output files with be written to the public folder. Set the EXPORT_BUILD_DIR env var to choose a different location.
The entry method. Run this to export the app to files.
The entry method . Run this to export the app to files .
def export! paths: nil, skips: [], filters: [], use_routes: nil, error_handler: nil,  &block
        @builder ||= 
          if self.builder
            self.builder
          else
            Builder.new(self, paths: paths, skips: skips, filters: filters, use_routes: use_routes, error_handler: error_handler )
          end
        @builder.build! &block
      end
def export! paths : nil , skips : [ ] , filters : [ ] , use_routes : nil , error_handler : nil , & block @builder ||= if self . builder self . builder else Builder . new ( self , paths : paths , skips : skips , filters : filters , use_routes : use_routes , error_handler : error_handler ) end @builder . build! & block end
The entry method.
The entry method .
paths
skips
filters
use_routes
error_handler
block
error_handler Define your own error handling. Takes one argument, a description of the error.
error_handler Define your own error handling . Takes one argument a description of the error .
]
Gives a Builder instance to the block  that is called for every path visited.
Gives a Builder instance to the block that is called for every path visited .
example
The default: Will use the paths from Sinatra Namespace app.export. # Skip a path (or paths) app.export. skips: ["/admin"] # Only visit the homepage and the site map app.export. paths: ["/", "/site-map"] # Visit the 404 error page by supplying the expected # status code (so as not to trigger an error) app.export. paths: ["/", ["/404.html",404]] # Filter out mentions of localhost:4567 filter = ->(content){ content.gsub("localhost:4567, "example.org") } app.export. filters: [filter] # Use routes found by Sinatra AdvancedRoutes *and # ones supplied via `paths` app.export. paths: ["/crazy/deep/page/path"], use_routes: true # Supply a path and scan the output for an internal link # adding it to the list of paths to be visited app.export. paths: "/" do |builder| if builder.last_response.body.include. "/echo-1" builder.paths << "/echo-1" end end
The default : Will use the paths from Sinatra Namespace app . export . # Skip a path ( or paths ) app . export . skips : [ " / admin " ] # Only visit the homepage and the site map app . export . paths : [ " / " " / site - map " ] # Visit the 404 error page by supplying the expected # status code ( so as not to trigger an error ) app . export . paths : [ " / " [ " / 404 . html " 404 ]] # Filter out mentions of localhost : 4567 filter = - > ( content ) { content . gsub ( " localhost : 4567 " example . org " ) } app . export . filters : [ filter ] # Use routes found by Sinatra AdvancedRoutes * and # ones supplied via ` paths ` app . export . paths : [ " / crazy / deep / page / path " ] use_routes : true # Supply a path and scan the output for an internal link # adding it to the list of paths to be visited app . export . paths : " / " do |builder| if builder . last_response . body . include . " / echo - 1 " builder . paths << " / echo - 1 " end end
note
By default the output files with be written to the public folder. Set the EXPORT_BUILD_DIR env var to choose a different location.
By default the output files with be written to the public folder . Set the EXPORT_BUILD_DIR env var to choose a different location .