Sha256: 61c3313a508e8e9e1a2ff24ca4f67b2d7bee9dc2a45b67145e63638bf79c1de1

Contents?: true

Size: 1.58 KB

Versions: 3

Compression:

Stored size: 1.58 KB

Contents

module Hippo
    module API
        module HelperMethods
            def hippo_application_title
                Extensions.controlling.title
            end

            def javascript_tags(*entries)
                Root.webpack.wait_until_available
                entries.map { |entry|
                    "<script src=\"#{Root.webpack.host}/assets/#{Root.webpack.file(entry)}\"></script>"
                }.join("\n")
            end

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

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

            def hippo_api_url
                Hippo.config.api_path
            end

            def error_as_json
                Hippo.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

            def find_template(views, name, engine, &block)
                views.each{ |v| super(v, name, engine, &block) }
            end
        end
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hippo-fw-0.9.5 lib/hippo/api/helper_methods.rb
hippo-fw-0.9.4 lib/hippo/api/helper_methods.rb
hippo-fw-0.9.3 lib/hippo/api/helper_methods.rb