lib/lhj/command/view.rb in lhj-tools-0.1.11 vs lib/lhj/command/view.rb in lhj-tools-0.1.12

- old
+ new

@@ -45,105 +45,121 @@ print_layout puts "\n\n" print_value end + def puts_d(str) + puts str.blue + end + + def puts_i(str) + puts str.blue + end + + def puts_l(str) + puts str.blue + end + + def puts_v(str) + puts str.blue + end + def print_declare names.each do |name| - puts '///' - puts "@property (nonatomic, strong) #{type} *#{name};" + puts_d '///' + puts_d "@property (nonatomic, strong) #{type} *#{name};" end end def print_instance names.each do |name| - puts "-(#{type} *)#{name}" - puts '{' - puts " if(!_#{name}){" + puts_i "-(#{type} *)#{name}" + puts_i '{' + puts_i " if(!_#{name}){" print_alloc(name) - puts " _#{name}.translatesAutoresizingMaskIntoConstraints = NO;" + puts_i " _#{name}.translatesAutoresizingMaskIntoConstraints = NO;" print_property(name) - puts ' }' - puts " return _#{name};" - puts '}' - puts "\n" + puts_i ' }' + puts_i " return _#{name};" + puts_i '}' + puts_i "\n" end end def print_alloc(name) case type when 'UIImageView' - puts " _#{name} = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"xxxx\"]];" + puts_i " _#{name} = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"xxxx\"]];" when 'UIButton' - puts " _#{name} = [UIButton buttonWithType:UIButtonTypeCustom];" + puts_i " _#{name} = [UIButton buttonWithType:UIButtonTypeCustom];" when 'UITableView' - puts " _#{name} = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];" + puts_i " _#{name} = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];" else - puts " _#{name} = [[#{type} alloc] init];" + puts_i " _#{name} = [[#{type} alloc] init];" end end def print_property(name) case type when 'UILabel' - puts " _#{name}.textColor = kSetCOLOR(0x333333);" - puts " _#{name}.text = @\"xxxxxxxx\";" - puts " _#{name}.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightRegular];" - puts " _#{name}.textAlignment = NSTextAlignmentCenter;" + puts_i " _#{name}.textColor = kSetCOLOR(0x333333);" + puts_i " _#{name}.text = @\"xxxxxxxx\";" + puts_i " _#{name}.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightRegular];" + puts_i " _#{name}.textAlignment = NSTextAlignmentCenter;" when 'UIImageView' - puts " _#{name}.backgroundColor = kBackgroundColor;" - puts " _#{name}.contentMode = UIViewContentModeScaleAspectFit;" - puts " _#{name}.clipsToBounds = YES;" - puts " _#{name}.layer.cornerRadius = 6.0f;" - puts " _#{name}.layer.borderColor = kLineColor.CGColor;" - puts " _#{name}.layer.borderWidth = 0.5;" + puts_i " _#{name}.backgroundColor = kBackgroundColor;" + puts_i " _#{name}.contentMode = UIViewContentModeScaleAspectFit;" + puts_i " _#{name}.clipsToBounds = YES;" + puts_i " _#{name}.layer.cornerRadius = 6.0f;" + puts_i " _#{name}.layer.borderColor = kLineColor.CGColor;" + puts_i " _#{name}.layer.borderWidth = 0.5;" when 'UITextField' - puts " _#{name}.textColor = kSetCOLOR(0x333333);" - puts " _#{name}.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightRegular];" + puts_i " _#{name}.textColor = kSetCOLOR(0x333333);" + puts_i " _#{name}.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightRegular];" when 'UIView' - puts " _#{name}.backgroundColor = kBackgroundColor;" + puts_i " _#{name}.backgroundColor = kBackgroundColor;" when 'UIStackView' - puts " _#{name}.axis = UILayoutConstraintAxisHorizontal;" - puts " _#{name}.distribution = UIStackViewDistributionFillEqually;" + puts_i " _#{name}.axis = UILayoutConstraintAxisHorizontal;" + puts_i " _#{name}.distribution = UIStackViewDistributionFillEqually;" when 'UITableView' - puts " _#{name}.backgroundColor = kBackgroundColor;" - puts " _#{name}.delegate = self;" - puts " _#{name}.delegate = self;" - puts " _#{name}.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];" - puts " _#{name}.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];" - puts " _#{name}.separatorStyle = UITableViewCellSeparatorStyleNone;" + puts_i " _#{name}.backgroundColor = kBackgroundColor;" + puts_i " _#{name}.delegate = self;" + puts_i " _#{name}.delegate = self;" + puts_i " _#{name}.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];" + puts_i " _#{name}.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];" + puts_i " _#{name}.separatorStyle = UITableViewCellSeparatorStyleNone;" when 'UIButton' - puts " _#{name}.backgroundColor = kBackgroundColor;" - puts " [_#{name} setTitle:@\"xxx\" forState:UIControlStateNormal];" - puts " [_#{name} setTitleColor:kSetCOLOR(0x999999) forState:UIControlStateNormal];" - puts " _#{name}.titleLabel.font = [UIFont systemFontOfSize:14.0 weight:UIFontWeightRegular];" - puts " [_#{name} setImage:[UIImage imageNamed:@\"xx\"] forState:UIControlStateNormal];" - puts " [_#{name} setImage:[UIImage imageNamed:@\"xx\"] forState:UIControlStateSelected];" - puts " [_#{name} addTarget:self action:@selector(actionHandler:) forControlEvents:UIControlEventTouchUpInside];" + puts_i " _#{name}.backgroundColor = kBackgroundColor;" + puts_i " [_#{name} setTitle:@\"xxx\" forState:UIControlStateNormal];" + puts_i " [_#{name} setTitleColor:kSetCOLOR(0x999999) forState:UIControlStateNormal];" + puts_i " _#{name}.titleLabel.font = [UIFont systemFontOfSize:14.0 weight:UIFontWeightRegular];" + puts_i " [_#{name} setImage:[UIImage imageNamed:@\"xx\"] forState:UIControlStateNormal];" + puts_i " [_#{name} setImage:[UIImage imageNamed:@\"xx\"] forState:UIControlStateSelected];" + puts_i " [_#{name} addTarget:self action:@selector(actionHandler:) forControlEvents:UIControlEventTouchUpInside];" end end def print_layout names.each do |name| - puts "[contentView addSubview:self.#{name}];" - puts "[self.#{name}.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor constant:0].active = YES;" - puts "[self.#{name}.trailingAnchor constraintEqualToAnchor:contentView.trailingAnchor constant:0].active = YES;" - puts "[self.#{name}.topAnchor constraintEqualToAnchor:contentView.topAnchor].active = YES;" - puts "[self.#{name}.bottomAnchor constraintEqualToAnchor:contentView.bottomAnchor].active = YES;" - puts "[self.#{name}.widthAnchor constraintEqualToConstant:80].active = YES;" - puts "[self.#{name}.heightAnchor constraintEqualToConstant:80].active = YES;" + puts_l "[contentView addSubview:self.#{name}];" + puts_l "[self.#{name}.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor constant:0].active = YES;" + puts_l "[self.#{name}.trailingAnchor constraintEqualToAnchor:contentView.trailingAnchor constant:0].active = YES;" + puts_l "[self.#{name}.topAnchor constraintEqualToAnchor:contentView.topAnchor].active = YES;" + puts_l "[self.#{name}.bottomAnchor constraintEqualToAnchor:contentView.bottomAnchor].active = YES;" + puts_l "[self.#{name}.widthAnchor constraintEqualToConstant:80].active = YES;" + puts_l "[self.#{name}.heightAnchor constraintEqualToConstant:80].active = YES;" if type.eql?('UILabel') - puts "[self.#{name} setContentHuggingPriority:300 forAxis:UILayoutConstraintAxisHorizontal];" - puts "[self.#{name} setContentCompressionResistancePriority:300 forAxis:UILayoutConstraintAxisHorizontal];" + puts_l "[self.#{name} setContentHuggingPriority:300 forAxis:UILayoutConstraintAxisHorizontal];" + puts_l "[self.#{name} setContentCompressionResistancePriority:300 forAxis:UILayoutConstraintAxisHorizontal];" end - puts "\n\n" + puts_l "\n\n" end end def print_value names.each do |name| if type.eql?('UILabel') - puts "self.#{name}.text = @\"xxxxx\";" + puts_v "self.#{name}.text = @\"xxxxx\";" end end end end