Module: StyleGuideAPI

Defined in:
lib/styleguide-api.rb,
lib/styleguide-api/version.rb

Defined Under Namespace

Modules: Helpers Classes: MiddlemanExtension

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.liveObject

Returns the value of attribute live.



9
10
11
# File 'lib/styleguide-api.rb', line 9

def live
  @live
end

.themeObject

Returns the value of attribute theme.



10
11
12
# File 'lib/styleguide-api.rb', line 10

def theme
  @theme
end

Class Method Details

.add_stylesheet(file) ⇒ Object



41
42
43
44
# File 'lib/styleguide-api.rb', line 41

def self.add_stylesheet(file)
  @stylesheets[theme] ||= []
  @stylesheets[theme] << file
end

.add_templates(glob, options = {}) ⇒ Object



35
36
37
38
39
# File 'lib/styleguide-api.rb', line 35

def self.add_templates(glob, options = {})
  current_theme = options[:theme] || theme
  @template_paths[current_theme] ||= []
  @template_paths[current_theme] << glob
end

.dataObject



23
24
25
26
27
28
# File 'lib/styleguide-api.rb', line 23

def self.data
  return @data if @data and not (live and @template_paths.any?)
  @data = {}
  load_templates
  @data
end

.initializeObject



13
14
15
16
17
18
19
20
# File 'lib/styleguide-api.rb', line 13

def self.initialize
  @live = false
  @templates = {}
  @template_paths = {}
  @data = nil
  @theme = nil
  @stylesheets = {}
end

.load(uri) ⇒ Object



30
31
32
33
# File 'lib/styleguide-api.rb', line 30

def self.load(uri)
  json = open(uri).read
  @data = JSON.parse(json)
end

.render(template_name, locals = {}, &block) ⇒ Object



46
47
48
49
50
# File 'lib/styleguide-api.rb', line 46

def self.render(template_name, locals = {}, &block)
  scope = locals.delete(:scope) || Object.new
  template = template_for(template_name)
  template.render(scope, locals, &block)
end

.stylesheetsObject



71
72
73
# File 'lib/styleguide-api.rb', line 71

def self.stylesheets
  data[theme]["stylesheets"] || []
end

.template_for(name) ⇒ Object



52
53
54
55
56
57
# File 'lib/styleguide-api.rb', line 52

def self.template_for(name)
  @templates[theme][name] if @templates[theme] && @templates[theme][name]
  template = data[theme]["templates"][name]
  @templates[theme] ||= {}
  @templates[theme][name] = Tilt[template["type"]].new { template["source"] }
end

.themesObject



63
64
65
# File 'lib/styleguide-api.rb', line 63

def self.themes
  (@template_paths.keys + (@data ? @data.keys : [])).uniq
end

.to_jsonObject



67
68
69
# File 'lib/styleguide-api.rb', line 67

def self.to_json
  data.to_json
end