Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
PrideChung committed Oct 20, 2013
1 parent 45a1a85 commit 3f1396a
Show file tree
Hide file tree
Showing 63 changed files with 7,771 additions and 1,510 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ profile
*.moved-aside
DerivedData
.idea/
*.fakgen.h
*.fakgen.m

Pods/
71 changes: 71 additions & 0 deletions CodeGenerators/CodeGenerator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
class CodeGenerator
attr_accessor :font_name, :names, :codes

def initialize(font_name, names, codes)
@font_name = font_name

@names = names.map do |name|
name.gsub(/[^0-9a-z]/i, '')
end

@codes = codes

if names.length != codes.length
raise 'names should be match to codes'
end
end

def generate
File.open("FAK#{@font_name}.fakgen.h", 'w+') { |f| f.write(generate_header) }
File.open("FAK#{@font_name}.fakgen.m", 'w+') { |f| f.write(generate_implementation) }
end

def generate_header
header = "// Generated Code\n"
@names.each do |name|
header_template = <<EOT
+ (instancetype)#{name}IconWithSize:(CGFloat)size;
EOT
header << header_template;
end
return header
end

def generate_implementation
implementation = "// Generated Code\n"

@names.each_with_index do |name, index|
implementation_template = <<EOT
+ (instancetype)#{name}IconWithSize:(CGFloat)size
{
return [self iconWithCode:@"#{@codes[index]}" size:size];
}
EOT
implementation << implementation_template
end

return implementation + "\n" + generate_icon_map
end

def generate_icon_map
icon_map = ''
@names.each_with_index do |name, index|
icon_map_template = <<EOT
@"#{@codes[index]}" : @"#{name}",
EOT
icon_map << icon_map_template
end
icon_map = <<EOT
+ (NSDictionary *)allIcons
{
return @{
#{icon_map}
};
}
EOT

return icon_map
end

end
Loading

0 comments on commit 3f1396a

Please sign in to comment.