Class: HtmlGrid::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/ydim/html/view/htmlgrid.rb

Constant Summary collapse

HTTP_HEADERS =
{
			"Cache-Control"	=>	"no-cache, max-age=3600, must-revalidate",
  'Content-Type'	=>	'text/html; charset=UTF-8',
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.escaped(*names) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/ydim/html/view/htmlgrid.rb', line 21

def escaped(*names)
	names.each { |name|
		define_method(name) { |model| 
			number_format escape(model.send(name))
		}
	}
end


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ydim/html/view/htmlgrid.rb', line 28

def links(event, *names)
	names.each { |name|
		define_method(name) { |model| 
			link = HtmlGrid::Link.new(name, model, @session, self)
			args = {:unique_id => model.unique_id}
			link.href = @lookandfeel._event_url(event, args)
			link.value = model.send(name)
			link
		}
	}
end

Instance Method Details

#escape(value) ⇒ Object



40
41
42
# File 'lib/ydim/html/view/htmlgrid.rb', line 40

def escape(value)
	CGI.escape(format(value))
end

#format(value) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/ydim/html/view/htmlgrid.rb', line 43

def format(value)
	case value
	when Float
		sprintf("%1.#{self.precision}f", value)
	else 
		value.to_s
	end
end

#number_format(string) ⇒ Object



51
52
53
54
55
# File 'lib/ydim/html/view/htmlgrid.rb', line 51

def number_format(string)
  string.reverse.gsub(/\d{3}(?=\d)(?!\d*\.)/) do |match|
    match << "'"
  end.reverse
end

#precisionObject



56
57
58
59
60
61
62
63
# File 'lib/ydim/html/view/htmlgrid.rb', line 56

def precision
	mdl = @session.state.model
	if(mdl.respond_to?(:precision))
		mdl.precision
	else
		2
	end
end