Module: Iftoc
- Defined in:
- lib/iftoc.rb,
lib/iftoc/version.rb
Constant Summary collapse
- VERSION =
"0.1.7"
Class Method Summary collapse
- .generateHFile(iconfontMap) ⇒ Object
- .generateMFile(iconFontName, iconfontMap) ⇒ Object
- .parseCSSFontName(file) ⇒ Object
- .parseCSSIconFont(file) ⇒ Object
- .parseSVGFontName(xmlContext) ⇒ Object
- .parseSVGIconFont(xmlContext) ⇒ Object
- .putStringToFile(text, path) ⇒ Object
Class Method Details
.generateHFile(iconfontMap) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/iftoc.rb', line 52 def generateHFile(iconfontMap) string1 = <<-EOB // // IconFont.h // AutoCoding // EOB string2 = <<-EOB // Copyright © 2017年 olinone. All rights reserved. // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #define theIconFont [IconFont shareInstance] @interface IconFont : NSObject + (instancetype)shareInstance; + (UIFont *)iconFontWithSize:(CGFloat)size; EOB hString = string1 + "// Created by AutoCoding on " + Time.new.strftime("%Y/%m/%d") + ".\n" + string2 iconfontMap.keys.each do |key| hString = hString + "@property (readonly) NSString *icon" + key + ";\n\n" end hString = hString + "@end" return hString end |
.generateMFile(iconFontName, iconfontMap) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/iftoc.rb', line 88 def generateMFile(iconFontName, iconfontMap) string1 = <<-EOB // // IconFont.m // AutoCoding // EOB string2 = <<-EOB // Copyright © 2017年 olinone. All rights reserved. // #import "IconFont.h" @implementation IconFont + (instancetype)shareInstance { static IconFont *iconFont = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ iconFont = [IconFont new]; }); return iconFont; } + (UIFont *)iconFontWithSize:(CGFloat)size { EOB mString = string1 + "// Created by AutoCoding on " + Time.new.strftime("%Y/%m/%d") + ".\n" + string2 + " return [UIFont fontWithName:@\"" + iconFontName + "\" size:size];" + "\n}\n\n" iconfontMap.each { |key, value| mString = mString + "- (NSString *)icon" + key + " {\n"; mString = mString + " return @\"\\U0000" + value + "\";" + "\n}\n\n" } mString = mString + "@end" return mString end |
.parseCSSFontName(file) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/iftoc.rb', line 27 def parseCSSFontName(file) file.each_line do |line| line.chomp! $fontNameRegexpStr =~ line fontName = $1 if fontName then return fontName end end return nil end |
.parseCSSIconFont(file) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/iftoc.rb', line 39 def parseCSSIconFont(file) iconfonts = Hash.new file.each_line do |line| line.chomp! $iconRegexpStr =~ line name = $1 if name then iconfonts[name] = $2 end end return iconfonts end |
.parseSVGFontName(xmlContext) ⇒ Object
9 10 11 12 |
# File 'lib/iftoc.rb', line 9 def parseSVGFontName(xmlContext) fontelement = xmlContext.root.elements["defs"].elements["font"] return fontelement.elements["font-face"].attributes["font-family"] end |
.parseSVGIconFont(xmlContext) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/iftoc.rb', line 14 def parseSVGIconFont(xmlContext) iconfonts = Hash.new fontelement = xmlContext.root.elements["defs"].elements["font"] fontelement.get_elements("glyph").each { |font| name = font.attributes["glyph-name"] unicode = font.attributes["unicode"].to_s.delete("#x;") if unicode.length == 4 then iconfonts[name] = unicode end } return iconfonts end |
.putStringToFile(text, path) ⇒ Object
128 129 130 131 132 |
# File 'lib/iftoc.rb', line 128 def putStringToFile(text, path) hio = File.open(path, "w+") hio.puts(text) hio.close end |