Module: YTag

Defined in:
lib/ytag.rb,
lib/ytag/tag.rb,
lib/ytag/bundle.rb

Overview

Defined Under Namespace

Classes: Bundle, Tag

Constant Summary collapse

NAME =
'ytag'
VERSION =
'0.0.1'
'Copyright (c) 2008 Ramsey Dow'

Class Method Summary collapse

Class Method Details



10
# File 'lib/ytag.rb', line 10

def self.copyright() YTag::COPYRIGHT end

.libdirObject



12
# File 'lib/ytag.rb', line 12

def self.libdir() File.expand_path(__FILE__).gsub(%r/\.rb$/, '') end

.tagify(tag) ⇒ Object

Raises:

  • (ArgumentError)


82
83
84
85
86
87
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
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/ytag/tag.rb', line 82

def self.tagify(tag)
  raise ArgumentError, 'nil tag' if tag.nil?
  raise ArgumentError, 'invalid tag class' if tag.class != String
  raise ArgumentError, 'empty tag' if tag.empty?

  # scrub all markup/scripting
  tag.scrub!(Tag::MARKUP)

  # from here on, tag may become empty and/or nil after any given operation

  # encode HTML entities
  tag = HTMLEntities.encode_entities(tag, :basic, :named) \
    if !tag.nil? && !tag.empty?

  # transform & => _amp_
  tag.gsub!('&', '_amp_') if !tag.nil? && !tag.empty?

  # transform & => _amp_
  tag.gsub!('&', '_amp_') if !tag.nil? && !tag.empty?

  # transform ? => _qm
  tag.gsub!('?', '_qm') if !tag.nil? && !tag.empty?

  # transform ! => _xpt
  tag.gsub!('!', '_xpt') if !tag.nil? && !tag.empty?

  # transform / => _fs_
  tag.gsub!('/', '_fs_') if !tag.nil? && !tag.empty?

  # transform \ => _bs_
  tag.gsub!('\\', '_bs_') if !tag.nil? && !tag.empty?

  # compress whitespace
  tag.squeeze(' \t') if !tag.nil? && !tag.empty?

  # delete undefined characters
  tag.delete!('=~@#$%^*()+[]{}|;:\'\"<>') if !tag.nil? && !tag.empty?

  # transform illegal separators
  tag.tr!(' ,.-', '_') if !tag.nil? && !tag.empty?

  # compress underscores
  tag.squeeze!('_') if !tag.nil? && !tag.empty?

  # remove preceding underscore
  tag = tag[1..-1] if !tag.nil? && !tag.empty? && tag[0].chr == '_'

  # remove trailing underscore
  tag = tag[0..tag.length-2] if !tag.nil? && !tag.empty? && tag[-1].chr == '_'

  # downcase
  tag.downcase! if !tag.nil? && !tag.empty?

  # handle nil or empty tags
  tag = Tag::BOGUS if tag.nil? || tag.empty?

  tag
end

.versionObject



11
# File 'lib/ytag.rb', line 11

def self.version() YTag::VERSION end