Class: HTMLSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/html-schema.rb,
lib/html-schema/dsl.rb,
lib/html-schema/api.rb,
lib/html-schema/object.rb,
lib/html-schema/helper.rb,
lib/html-schema/railtie.rb,
lib/html-schema/microdata.rb,
lib/html-schema/attribute.rb,
lib/html-schema/api/object.rb,
lib/html-schema/microformat.rb,
lib/html-schema/api/attribute.rb,
lib/html-schema/configuration.rb,
lib/html-schema/microdata/object.rb,
lib/html-schema/microformat/object.rb,
lib/html-schema/microdata/attribute.rb,
lib/html-schema/microformat/attribute.rb

Defined Under Namespace

Modules: DSL, Helper Classes: API, Attribute, Configuration, Microdata, Microformat, Object, Railtie

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types = {}) ⇒ HTMLSchema

Returns a new instance of HTMLSchema



41
42
43
44
# File 'lib/html-schema.rb', line 41

def initialize(types = {})
  self.class.instance = self
  api.types.keys.each { |key| define_api_method(key) }
end

Class Method Details

.[](key) ⇒ Object



19
20
21
# File 'lib/html-schema.rb', line 19

def [](key)
  api[key]
end

.bootstrap!(format) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/html-schema.rb', line 31

def bootstrap!(format)
  format_name = format == :api ? "API" : format.to_s.camelize
  Dir["#{HTMLSchema.root}/html-schema/#{format}/**/*.rb"].inject({}) do |hash, file|
    name = ::File.basename(file, File.extname(file))
    hash[name.to_sym] = "::HTMLSchema::#{format_name}::#{name.camelize}".constantize.new if name !~ /^(base|feed|attribute)$/
    hash
  end
end

.configurationObject



15
16
17
# File 'lib/html-schema.rb', line 15

def configuration
  @configuration ||= HTMLSchema::Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



11
12
13
# File 'lib/html-schema.rb', line 11

def configure(&block)
  yield configuration
end

.instanceObject



23
24
25
# File 'lib/html-schema.rb', line 23

def instance
  @instance ||= new
end

.instance=(value) ⇒ Object



27
28
29
# File 'lib/html-schema.rb', line 27

def instance=(value)
  @instance = value
end

.rootObject



7
8
9
# File 'lib/html-schema.rb', line 7

def root
  @root ||= File.dirname(File.expand_path(__FILE__))
end

Instance Method Details

#apiObject



46
47
48
# File 'lib/html-schema.rb', line 46

def api
  @api          ||= HTMLSchema::API
end

#each(&block) ⇒ Object

todo, iterate through tree, so you can visualize it however you want.



59
60
61
# File 'lib/html-schema.rb', line 59

def each(&block)
  
end

#microdataObject



50
51
52
# File 'lib/html-schema.rb', line 50

def microdata
  @microdata    ||= HTMLSchema::Microdata
end

#microformatObject



54
55
56
# File 'lib/html-schema.rb', line 54

def microformat
  @microformat  ||= HTMLSchema::Microformat
end

#to_hash(options = {}) ⇒ Object



63
64
65
66
67
68
# File 'lib/html-schema.rb', line 63

def to_hash(options = {})
  recursively_stringify_keys(api.types.keys.inject({}) do |hash, key|
    hash[key] = api.types[key].to_object
    hash
  end, options)
end

#to_yamlObject



70
71
72
# File 'lib/html-schema.rb', line 70

def to_yaml
  to_hash.to_yaml
end