lib/sinatra/export.rb
# Builds the output dirs and file
# based on the response.
# @param [String] path
# @param [Pathname,String] dir
# @param [Rack::MockResponse] response
# @return [String] file_path
Builds the output dirs and file
based on the response.
Builds the output dirs and file based on the response .
def build_path(path: nil, dir: nil, response: nil)
          fail ArgumentError, "'path' is a required argument to build_path" if path.nil?
          fail ArgumentError, "'dir' is a required argument to build_path" if dir.nil?
          fail ArgumentError, "'response' is a required argument to build_path" if response.nil?
          body = response.body
          mtime = response.headers.key?("Last-Modified") ?
            Time.httpdate(response.headers["Last-Modified"]) : Time.now
          pattern = %r{
            [^/\.]+
            \.
            (
              #{app.settings.export_extensions.join("|")}
            )
          $}x
          file_path = Pathname( File.join dir, path )
          file_path = file_path.join( 'index.html' ) unless  path.match(pattern)
          ::FileUtils.mkdir_p( file_path.dirname )
          write_path content: body, path: file_path
          ::FileUtils.touch(file_path, :mtime => mtime)
          file_path
        end
def build_path ( path : nil , dir : nil , response : nil ) fail ArgumentError , "'path' is a required argument to build_path" if path . nil? fail ArgumentError , "'dir' is a required argument to build_path" if dir . nil? fail ArgumentError , "'response' is a required argument to build_path" if response . nil? body = response . body mtime = response . headers . key? ( "Last-Modified" ) ? Time . httpdate ( response . headers [ "Last-Modified" ] ) : Time . now pattern = %r{ 
            [^/ \. ]+
             \. 
            (
               #{ app . settings . export_extensions . join ( "|" ) } 
            )
          $ }x file_path = Pathname ( File . join dir , path ) file_path = file_path . join ( 'index.html' ) unless path . match ( pattern ) :: FileUtils . mkdir_p ( file_path . dirname ) write_path content : body , path : file_path :: FileUtils . touch ( file_path , :mtime => mtime ) file_path end
Builds the output dirs and file
based on the response.
Builds the output dirs and file based on the response .
# These argument checks are for Ruby v2.0 as it # doesn't support required keyword args.
None
String
path
dir
response
None