Module: Purpur

Defined in:
lib/purpur.rb,
lib/purpur/engine.rb,
lib/purpur/helpers.rb,
lib/purpur/version.rb,
lib/purpur/generator.rb

Defined Under Namespace

Modules: Helpers Classes: Engine, Generator

Constant Summary collapse

ICON_SIZES =
({
  xsmall: 'xsm',
  extrasmall: 'xsm',
  xsm: 'xsm',
  small: 'sm',
  sm: 'sm',
  medium: 'm',
  m: 'm',
  md: 'm',
  large: 'lg',
  lg: 'lg',
  big: 'xl',
  xl: 'xl',
  huge: 'xxl',
  xxl: 'xxl'
}).with_indifferent_access
ICON_EXTENTION =
'.svg'
ICON_SYNONIMS_HASH =
if File.exists? File.join("config", "icon_synonims.yml")
  YAML.load(ERB.new(IO.read(File.join("config", "icon_synonims.yml"))).result)
else
  {}
end
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.assets_dirObject



76
77
78
# File 'lib/purpur.rb', line 76

def assets_dir
  File.join(root_dir, 'app', 'assets')
end

.icon_key(n) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/purpur.rb', line 43

def icon_key(n)
  case n
  when Symbol, String
    n.downcase
  when Class
    n.name.to_s.downcase
  when Object
    n.class.name.to_s.downcase
  end
end

.icon_name(key) ⇒ Object



54
55
56
# File 'lib/purpur.rb', line 54

def icon_name(key)
  icon_names[icon_synonim(icon_key(key))]
end

.icon_namesObject



88
89
90
91
92
93
94
95
96
# File 'lib/purpur.rb', line 88

def icon_names
  Hash[
    self.icons.map {|i|
      [File.basename(i, ICON_EXTENTION), File.basename(i, ICON_EXTENTION)]
    }
  ].tap do |h|
    h.default_proc = ->(_, i) { Rails.logger.warn("'#{i}' is wrong icon name. Use one of #{h.keys.join(', ')}"); i.to_s }
  end
end

.icon_size(size) ⇒ Object



33
34
35
# File 'lib/purpur.rb', line 33

def icon_size(size)
  ICON_SIZES[size]
end

.icon_synonim(key) ⇒ Object



37
38
39
40
41
# File 'lib/purpur.rb', line 37

def icon_synonim(key)
  (ICON_SYNONIMS_HASH.with_indifferent_access.tap do |h|
    h.default_proc = ->(_, i) { i.to_s }
  end)[key]
end

.iconsObject



84
85
86
# File 'lib/purpur.rb', line 84

def icons
  Dir[File.join(self.images_dir, "*#{ICON_EXTENTION}")]
end

.images_dirObject



80
81
82
# File 'lib/purpur.rb', line 80

def images_dir
  File.join(assets_dir, 'icons')
end

.rails?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/purpur.rb', line 64

def rails?
  defined?(::Rails::Engine)
end

.register!Object



58
59
60
61
62
# File 'lib/purpur.rb', line 58

def register!
  register_helpers
  register_engine     if rails?
  register_sprockets  if sprockets?
end

.root_dirObject



72
73
74
# File 'lib/purpur.rb', line 72

def root_dir
  File.expand_path "."
end

.sprite_fileObject



98
99
100
# File 'lib/purpur.rb', line 98

def sprite_file
  File.join(assets_dir, 'images', 'purpur.svg')
end

.sprockets?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/purpur.rb', line 68

def sprockets?
  defined?(::Sprockets)
end