Module: Cowtech::RubyOnRails::Helpers::ApplicationHelper

Defined in:
app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#_normalize_type(format = nil) ⇒ Object



54
55
56
57
# File 'app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb', line 54

def _normalize_type(format = nil)
	format = :text if !([:text, :json, :jsonp].include?(format))
	format
end

#additional_tag(what = :js, *args) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb', line 27

def additional_tag(what = :js, *args)
	if what == :js then
		args.insert(0, "app/#{self.full_controller_name}.js")
		javascript_include_tag(*args)
	elsif what == :css then
		args.insert(0, "app/#{self.full_controller_name}.css")
		stylesheet_link_tag(*args)
	end
end

#application_infoObject



11
12
13
14
# File 'app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb', line 11

def application_info
	@application_info = YAML.load_file(Rails.root + "config/application_info.yml") if !@application_info
	@application_info
end

#custom_respond_with(data, format = nil, status = :ok) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb', line 63

def custom_respond_with(data, format = nil, status = :ok)
	return if performed?

	format = request.format if format.blank?
	format = self._normalize_type(format)

	if format == :text then
		render :text => data, :status => status
	elsif format == :json then
		render :json => data, :status => status
	elsif format == :jsonp then
		render :json => data, :status => status, :callback => params[:callback]
	end
end

#debug(what, type = :yaml) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb', line 78

def debug(what, type = :yaml)
	msg = ""

	if type == :json then
		begin
			msg = JSON.pretty_generate(what)
		rescue Exception => e
			msg = what.to_json
		end
	elsif type == :yaml then
		msg = what.to_yaml
	else
		msg = what.inspect
	end

	rv = ""
	case type.to_sym
		when :json
			rv = render_to_string(:json => msg)
		else
			rv = render_to_string(:text => msg)
	end

	self.response_body = rv
end

#full_controller_name(css = false) ⇒ Object



16
17
18
19
# File 'app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb', line 16

def full_controller_name(css = false)
	rv = self.controller_path
	!css ? rv : rv.gsub("/", "_")
end

#get_data(key = nil, default = "") ⇒ Object



41
42
43
# File 'app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb', line 41

def get_data(key = nil, default = "")
	@controller_data.is_a?(Hash) ? @controller_data.fetch(key.to_sym, default) : default
end

#get_param(key, default = nil) ⇒ Object



50
51
52
# File 'app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb', line 50

def get_param(key, default = nil)
	params[key].blank? ? default : params[key]
end

#google_font_stylesheet(font, additional = nil, version = "1") ⇒ Object



37
38
39
# File 'app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb', line 37

def google_font_stylesheet(font, additional = nil, version = "1")
	stylesheet_link_tag("http://fonts.googleapis.com/css?family=#{CGI.escape(font)}#{additional}&v=#{version}", :media => :all)
end

#location_name(action = nil, controller = nil) ⇒ Object



21
22
23
24
25
# File 'app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb', line 21

def location_name(action = nil, controller = nil)
	controller = self.full_controller_name if !controller
	action = self.action_name if !action
	"#{controller}##{action}"
end

#set_data(key, value) ⇒ Object



45
46
47
48
# File 'app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb', line 45

def set_data(key, value)
	@controller_data = {} if !(defined?(@controller_data) && @controller_data.is_a?(Hash))
	@controller_data[key.to_sym] = value
end

#setup_json_response(type = :base) ⇒ Object



59
60
61
# File 'app/helpers/cowtech/ruby_on_rails/helpers/application_helper.rb', line 59

def setup_json_response(type = :base)
	ApplicationController.setup_json_response(type)
end