Sha256: 299624c930a7ab005ad5bef1530836142e1bbba4e699376ab348e80d35904d50

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

module Lanes
    module API
        module HelperMethods
            def lanes_application_title
                Extensions.controlling.title
            end

            def lanes_javascript_tags
                javascript_tag('lanes/vendor') + "\n" + javascript_tag('lanes')
            end

            def lanes_stylesheet_tags
                stylesheet_tag('lanes')
            end

            def client_bootstrap_data(mergedWith: {})
                API.to_json(Extensions.client_bootstrap_data(self).merge(mergedWith))
            end

            def csrf_token
                Rack::Csrf.csrf_token(env)
            end

            def lanes_api_url
                Lanes.config.api_path
            end

            def error_as_json
                Lanes.logger.warn request.env['sinatra.error']
                API.to_json(
                    success: false,
                    errors:  { exception: request.env['sinatra.error'].message },
                    message: request.env['sinatra.error'].message
                )
            end

            def data
                @json_data ||= Oj.load( request.body.read )
            end

            def request_origin
                @request_origin ||= env['HTTP_ORIGIN']
            end

            def json_reply(response)
                content_type 'application/json'
                API.to_json(response)
            end
        end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lanes-0.7.0 lib/lanes/api/helper_methods.rb