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 ios8 ios9 ios10)
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, other_style = nil) ⇒ Object
- .styles ⇒ Object
- .to_key(key) ⇒ Object
Class Method Details
.add_style_sheet(name, properties, os_version = :all) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/plastic_cup/base.rb', line 22 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
31 32 33 34 35 36 37 38 39 |
# File 'lib/plastic_cup/base.rb', line 31 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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/plastic_cup/base.rb', line 41 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
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/plastic_cup/base.rb', line 60 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
84 85 86 |
# File 'lib/plastic_cup/base.rb', line 84 def self.handlers @handlers ||= Hash.new{ |hash,klass| hash[klass] = {} } end |
.style(target, style, other_style = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/plastic_cup/base.rb', line 7 def self.style(target, style, other_style=nil) if style.is_a?(Hash) apply_properties(target, style) else extends = style.is_a?(Array) ? style : [style] final_style = {} extends.each do |ext| final_style.merge!(get_style_sheet_properties(ext)) end final_style.merge!(other_style) if other_style.is_a?(Hash) apply_properties(target, final_style) end target end |
.styles ⇒ Object
79 80 81 |
# File 'lib/plastic_cup/base.rb', line 79 def self.styles @styles||={} end |
.to_key(key) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/plastic_cup/base.rb', line 71 def self.to_key(key) begin key = key.to_sym rescue NoMethodError raise TypeError.new "#{key.inspect} is not a symbol" end end |