Module: Lanes::API::HelperMethods

Defined in:
lib/lanes/api/helper_methods.rb

Instance Method Summary collapse

Instance Method Details

#client_bootstrap_data(mergedWith: {}) ⇒ Object



22
23
24
# File 'lib/lanes/api/helper_methods.rb', line 22

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

#csrf_tokenObject



26
27
28
# File 'lib/lanes/api/helper_methods.rb', line 26

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

#dataObject



43
44
45
# File 'lib/lanes/api/helper_methods.rb', line 43

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

#error_as_jsonObject



34
35
36
37
38
39
40
41
# File 'lib/lanes/api/helper_methods.rb', line 34

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

#json_reply(response) ⇒ Object



51
52
53
54
# File 'lib/lanes/api/helper_methods.rb', line 51

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

#lanes_api_urlObject



30
31
32
# File 'lib/lanes/api/helper_methods.rb', line 30

def lanes_api_url
    Lanes.config.api_path
end

#lanes_application_titleObject



4
5
6
# File 'lib/lanes/api/helper_methods.rb', line 4

def lanes_application_title
    Extensions.controlling.title
end

#lanes_javascript_tagsObject



8
9
10
11
12
13
14
15
16
# File 'lib/lanes/api/helper_methods.rb', line 8

def lanes_javascript_tags
    assets = API.webpack.assets.map do | k |
        "<script src=\"http://localhost:#{API.webpack.port}/#{k}\"></script>"
    end
    assets.join("\n")

    # "<script src=\"http://localhost:#{API.webpack.port}/lanes.js\"></script>"
    # javascript_tag('lanes/vendor') + "\n" + javascript_tag('lanes')
end

#lanes_stylesheet_tagsObject



18
19
20
# File 'lib/lanes/api/helper_methods.rb', line 18

def lanes_stylesheet_tags
    # stylesheet_tag('lanes')
end

#request_originObject



47
48
49
# File 'lib/lanes/api/helper_methods.rb', line 47

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