Class: PlasticCup::Base
- Inherits:
-
Object
- Object
- PlasticCup::Base
- Defined in:
- lib/plastic_cup/base.rb
Constant Summary collapse
- OSVersions =
%w(all ios4 ios5 ios6 ios7)
Class Method Summary collapse
- .add_style_sheet(name, properties, os_version = :all) ⇒ Object
- .get_style_sheet(style) ⇒ Object
- .get_style_sheet_properties(style) ⇒ Object
-
.handler(klass, *style_names, &block) ⇒ Object
teacup/lib/teacup/handler.rb.
-
.handlers ⇒ Object
teacup/lib/teacup/handler.rb.
- .style(target, style) ⇒ Object
- .styles ⇒ Object
- .to_key(key) ⇒ Object
Class Method Details
.add_style_sheet(name, properties, os_version = :all) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/plastic_cup/base.rb', line 16 def self.add_style_sheet(name, properties, os_version=:all) if OSVersions.include?(os_version.to_s) styles[to_key(name)] ||= {} styles[to_key(name)][os_version.to_sym] = Stylesheet.new(properties) else raise ArgumentError.new "OS version only accept #{OSVersions}" end end |
.get_style_sheet(style) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/plastic_cup/base.rb', line 25 def self.get_style_sheet(style) version_string = UIDevice.currentDevice.systemVersion.split('.').first if styles[to_key(style)].is_a?(Hash) style_hash = styles[to_key(style)]["ios#{version_string}".to_sym] style_hash ||= styles[to_key(style)][:all] end NSLog "WARNING: Style #{style} undefined." if style_hash.nil? style_hash end |
.get_style_sheet_properties(style) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/plastic_cup/base.rb', line 35 def self.get_style_sheet_properties(style) style_sheet = get_style_sheet(style) if style_sheet.nil? {} else extends = style_sheet.extends if extends.empty? style_sheet.properties else final_style = {} extends.each do |ext| final_style.merge!(get_style_sheet_properties(ext)) end final_style.merge(style_sheet.properties) end end end |
.handler(klass, *style_names, &block) ⇒ Object
teacup/lib/teacup/handler.rb
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/plastic_cup/base.rb', line 54 def self.handler(klass, *style_names, &block) if style_names.length == 0 raise TypeError.new "No style names assigned" else style_names.each do |style_name| handlers[klass.name][to_key(style_name)] = block end end self end |
.handlers ⇒ Object
teacup/lib/teacup/handler.rb
78 79 80 |
# File 'lib/plastic_cup/base.rb', line 78 def self.handlers @handlers ||= Hash.new{ |hash,klass| hash[klass] = {} } end |
.style(target, style) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/plastic_cup/base.rb', line 7 def self.style(target, style) if style.is_a?(Hash) apply_properties(target, style) else apply_properties(target, get_style_sheet_properties(style)) end target end |
.styles ⇒ Object
73 74 75 |
# File 'lib/plastic_cup/base.rb', line 73 def self.styles @styles||={} end |
.to_key(key) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/plastic_cup/base.rb', line 65 def self.to_key(key) begin key = key.to_sym rescue NoMethodError raise TypeError.new "#{key.inspect} is not a symbol" end end |