Class: Redmine::Views::Builders::Json

Inherits:
Structure
  • Object
show all
Defined in:
lib/redmine/views/builders/json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Structure

#array, #encode_value, #method_missing

Constructor Details

#initialize(request, response) ⇒ Json

Returns a new instance of Json

Since:

  • 2.1.0



26
27
28
29
30
31
32
# File 'lib/redmine/views/builders/json.rb', line 26

def initialize(request, response)
  super
  callback = request.params[:callback] || request.params[:jsonp]
  if callback && Setting.jsonp_enabled?
    self.jsonp = callback.to_s.gsub(/[^a-zA-Z0-9_.]/, '')
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Redmine::Views::Builders::Structure

Instance Attribute Details

#jsonpObject

Returns the value of attribute jsonp

Since:

  • 2.1.0



24
25
26
# File 'lib/redmine/views/builders/json.rb', line 24

def jsonp
  @jsonp
end

Instance Method Details

#outputObject

Since:

  • 1.1.0



34
35
36
37
38
39
40
41
# File 'lib/redmine/views/builders/json.rb', line 34

def output
  json = @struct.first.to_json
  if jsonp.present?
    json = "#{jsonp}(#{json})"
    @response.content_type = 'application/javascript'
  end
  json
end