Module: Lanes::API::HelperMethods
- Defined in:
- lib/lanes/api/helper_methods.rb
Instance Method Summary collapse
- #client_bootstrap_data(mergedWith: {}) ⇒ Object
- #csrf_token ⇒ Object
- #data ⇒ Object
- #error_as_json ⇒ Object
- #json_reply(response) ⇒ Object
- #lanes_api_url ⇒ Object
- #lanes_application_title ⇒ Object
- #lanes_javascript_tags ⇒ Object
- #lanes_stylesheet_tags ⇒ Object
- #request_origin ⇒ Object
Instance Method Details
#client_bootstrap_data(mergedWith: {}) ⇒ Object
23 24 25 |
# File 'lib/lanes/api/helper_methods.rb', line 23 def client_bootstrap_data(mergedWith: {}) API.to_json(Extensions.client_bootstrap_data.merge(mergedWith)) end |
#csrf_token ⇒ Object
27 28 29 |
# File 'lib/lanes/api/helper_methods.rb', line 27 def csrf_token Rack::Csrf.csrf_token(env) end |
#data ⇒ Object
44 45 46 |
# File 'lib/lanes/api/helper_methods.rb', line 44 def data @json_data ||= Oj.load( request.body.read ) || {} end |
#error_as_json ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/lanes/api/helper_methods.rb', line 35 def error_as_json Lanes.logger.warn request.env['sinatra.error'] API.to_json( success: false, errors: { exception: request.env['sinatra.error']. }, message: request.env['sinatra.error']. ) end |
#json_reply(response) ⇒ Object
52 53 54 55 |
# File 'lib/lanes/api/helper_methods.rb', line 52 def json_reply(response) content_type 'application/json' API.to_json(response) end |
#lanes_api_url ⇒ Object
31 32 33 |
# File 'lib/lanes/api/helper_methods.rb', line 31 def lanes_api_url Lanes.config.api_path end |
#lanes_application_title ⇒ Object
4 5 6 |
# File 'lib/lanes/api/helper_methods.rb', line 4 def lanes_application_title Extensions.controlling.title end |
#lanes_javascript_tags ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/lanes/api/helper_methods.rb', line 8 def [] # 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_tags ⇒ Object
19 20 21 |
# File 'lib/lanes/api/helper_methods.rb', line 19 def # stylesheet_tag('lanes') end |
#request_origin ⇒ Object
48 49 50 |
# File 'lib/lanes/api/helper_methods.rb', line 48 def request_origin @request_origin ||= env['HTTP_ORIGIN'] end |