Skip to content
This repository has been archived by the owner on Feb 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #42 from meetup/android_xml_changes_redux
Browse files Browse the repository at this point in the history
more android XML changes
  • Loading branch information
akdetrick committed Jan 27, 2015
2 parents 99edb74 + 495bd53 commit f284c3b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 56 deletions.
86 changes: 42 additions & 44 deletions android/colors.xml
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated code: DO NOT EDIT -->
<!-- Last update: January 26, 2015 -->
<resources>

<!-- Base color palette -->
<!-- -->
<color name="white">#ffffffff</color>
<color name="dark_gray">#ff353e48</color>
<color name="medium_gray">#ffe6e9ec</color>
<color name="light_gray">#fff3f6f9</color>
<color name="red">#ffd55741</color>
<color name="green">#ff8cbf6a</color>
<color name="blue">#ff3987cb</color>
<color name="light_blue">#ff68a5d9</color>
<color name="purple">#ff7160aa</color>
<color name="brown">#ff713f19</color>
<color name="yellow">#fff0cb4f</color>
<color name="foundation_white">#ffffffff</color>
<color name="foundation_dark_gray">#ff353e48</color>
<color name="foundation_medium_gray">#ffe6e9ec</color>
<color name="foundation_light_gray">#fff3f6f9</color>
<color name="foundation_red">#ffd55741</color>
<color name="foundation_green">#ff8cbf6a</color>
<color name="foundation_blue">#ff3987cb</color>
<color name="foundation_light_blue">#ff68a5d9</color>
<color name="foundation_purple">#ff7160aa</color>
<color name="foundation_brown">#ff713f19</color>
<color name="foundation_yellow">#fff0cb4f</color>

<!-- Text colors -->
<!-- -->
<color name="text_primary">#de000000</color>
<color name="text_secondary">#8a000000</color>
<color name="text_tertiary">#42000000</color>
<color name="text_primary_inverted">#ffffffff</color>
<color name="text_secondary_inverted">#b3ffffff</color>
<color name="text_tertiary_inverted">#4dffffff</color>
<color name="foundation_text_primary">#de000000</color>
<color name="foundation_text_secondary">#8a000000</color>
<color name="foundation_text_tertiary">#42000000</color>
<color name="foundation_text_primary_inverted">#ffffffff</color>
<color name="foundation_text_secondary_inverted">#b3ffffff</color>
<color name="foundation_text_tertiary_inverted">#4dffffff</color>

<!-- UI Colors -->
<!-- -->
<color name="accent">#ffd55741</color>
<color name="link">#ff3987cb</color>
<color name="border">#1f000000</color>
<color name="border_inverted">#33ffffff</color>
<color name="overlay_pressed">#1a000000</color>
<color name="modal_shade">#bf000000</color>
<color name="shade">#0d000000</color>
<color name="shade_inverted">#1affffff</color>
<color name="text_protection">#0d000000</color>
<color name="foundation_accent">@color/foundation_red</color>
<color name="foundation_link">@color/foundation_blue</color>
<color name="foundation_border">#1f000000</color>
<color name="foundation_border_inverted">#33ffffff</color>
<color name="foundation_overlay_pressed">#1a000000</color>
<color name="foundation_modal_shade">#bf000000</color>
<color name="foundation_shade">#0d000000</color>
<color name="foundation_shade_inverted">#1affffff</color>
<color name="foundation_text_protection">@color/foundation_shade</color>

<!-- Background colors -->
<!-- -->
<color name="content_bg">#ffffffff</color>
<color name="content_bg_inverted">#ff353e48</color>
<color name="collection_bg_dark">#ffe6e9ec</color>
<color name="collection_bg_light">#fff3f6f9</color>
<color name="foundation_content_bg">@color/foundation_white</color>
<color name="foundation_content_bg_inverted">#ff353e48</color>
<color name="foundation_collection_bg_dark">#ffe6e9ec</color>
<color name="foundation_collection_bg_light">#fff3f6f9</color>

<!-- EXTERNAL -->
<!-- third party colors -->
<color name="facebook">#ff3b5998</color>
<color name="twitter">#ff33ccff</color>
<color name="linkedin">#ff4875b4</color>
<color name="tumblr">#ff2b4964</color>
<color name="flickr">#fffe0883</color>
<color name="foursquare">#ff0cbadf</color>
<color name="googleplus">#ffc63d2d</color>
<color name="instagram">#ff4e433c</color>
<color name="reddit">#ffcee3f8</color>
<color name="wepay">#ff4891dc</color>
<color name="foundation_facebook">#ff3b5998</color>
<color name="foundation_twitter">#ff33ccff</color>
<color name="foundation_linkedin">#ff4875b4</color>
<color name="foundation_tumblr">#ff2b4964</color>
<color name="foundation_flickr">#fffe0883</color>
<color name="foundation_foursquare">#ff0cbadf</color>
<color name="foundation_googleplus">#ffc63d2d</color>
<color name="foundation_instagram">#ff4e433c</color>
<color name="foundation_reddit">#ffcee3f8</color>
<color name="foundation_wepay">#ff4891dc</color>
</resources>
32 changes: 20 additions & 12 deletions src/build.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
require 'yaml'
require 'psych'
require 'json'
require 'erb'
require 'builder'
require 'time'

$: << File.dirname(__FILE__)
require 'lib/string_exts'

color_types = YAML.load_file("./colors.yaml")
color_types = Psych.load_file("./colors.yaml")

# SPECIMEN HTML
@color_types = color_types
Expand Down Expand Up @@ -43,19 +44,27 @@
end

# ANDROID
mapping = Psych.parse_file("colors.yaml").root
File.open("../android/colors.xml", 'w+') do |file|
xml = Builder::XmlMarkup.new(:target => file, :indent => 2)
xml.instruct!
xml.comment! "Generated code: DO NOT EDIT"
xml.comment! "Last update: #{Time.now.strftime('%B %d, %Y')}"
xml.resources do
color_types.each_value do |color_type|
mapping.children.each_slice(2) do |ignore, color_type|
xml << "\n"
xml.comment! color_type["name"]
xml.comment! color_type["comment"]
color_type["colors"].each do |key, value|
vals = value.rotate(-1)
vals[0] = (vals[0] * 255).round # 1.0 -> 0xff
hexcolor = "#" + vals.map{|c| "%02x" % c.to_i}.join
xml.color hexcolor, {name: key.underscore}
xml.comment! color_type.children[1].value
comment = color_type.children[3].value
xml.comment! comment unless comment.empty?
color_type.children[5].children.each_slice(2) do |key, value|
if value.is_a?(Psych::Nodes::Sequence)
vals = value.children.rotate(-1).map{|n| n.value.to_f}
vals[0] = (vals[0] * 255).round # 1.0 -> 0xff
hexcolor = "#" + vals.map{|c| "%02x" % c.to_i}.join
else
hexcolor = "@color/foundation_#{value.anchor.underscore}"
end
xml.color hexcolor, {name: "foundation_#{key.value.underscore}"}
end
end
end
Expand All @@ -64,7 +73,6 @@

# IOS
def ios_file_comment_lines(class_name, is_header)
require 'time'
filename = is_header ? "#{class_name}.h" : "#{class_name}.m"
import_line = is_header ? '@import UIKit;' : %(#import "#{class_name}.h")
return [
Expand All @@ -84,7 +92,7 @@ def ios_lines(class_name, is_header)
header_lines = ios_file_comment_lines(class_name, is_header)
header_lines << (is_header ? "@interface #{class_name} : NSObject" : "@implementation #{class_name}") << ''

color_types = YAML.load_file('./colors.yaml')
color_types = Psych.load_file('./colors.yaml')
color_types.each do |color_type_key, color_type|
header_lines << "#pragma mark - #{color_type['name']}"
header_lines << ''
Expand Down

0 comments on commit f284c3b

Please sign in to comment.