Class: QEDProject::Libraries::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/qedproject/libraries/base.rb

Direct Known Subclasses

Backbone, JQuery, JQuerytmpl, Knockout, Skeleton

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#render_template_to_file

Constructor Details

#initialize(project) ⇒ Base

Returns a new instance of Base.



73
74
75
76
77
# File 'lib/qedproject/libraries/base.rb', line 73

def initialize(project) 
  @project = project
  @lib_root = File.join(@project.vendor_root, self.library.to_s)
  @template_root = File.join(@lib_root, "templates")
end

Class Attribute Details

.libsObject

Returns the value of attribute libs.



10
11
12
# File 'lib/qedproject/libraries/base.rb', line 10

def libs
  @libs
end

Instance Attribute Details

#lib_rootObject

Returns the value of attribute lib_root.



7
8
9
# File 'lib/qedproject/libraries/base.rb', line 7

def lib_root
  @lib_root
end

#projectObject

Returns the value of attribute project.



7
8
9
# File 'lib/qedproject/libraries/base.rb', line 7

def project
  @project
end

#template_rootObject

Returns the value of attribute template_root.



7
8
9
# File 'lib/qedproject/libraries/base.rb', line 7

def template_root
  @template_root
end

Class Method Details

.library(name) ⇒ Object

Support for DSL, for setting the library name when creating the adapter. Adds the library and class to QEDProject::Libraries::Base.libs hash and also creates a getter method on the adapter instance



16
17
18
19
20
21
22
23
24
# File 'lib/qedproject/libraries/base.rb', line 16

def library(name)
  QEDProject::Libraries::Base.libs ||= {}
  QEDProject::Libraries::Base.libs[name] = self
  class_eval do
    define_method :library do
      name
    end
  end
end

.set_css_files(files) ⇒ Object

convenience method for the DSL for setting CSS files



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/qedproject/libraries/base.rb', line 42

def set_css_files(files)
  # define class method to get the data out
   m = class << self; self; end
   m.send :define_method, :css_files do
     files
   end
  
  class_eval do
    define_method :css_files do
      files
    end
  end
end

.set_image_files(files) ⇒ Object

convenience method for the DSL for setting image files.



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/qedproject/libraries/base.rb', line 58

def set_image_files(files)

  m = class << self; self; end
  m.send :define_method, :image_files do
    files
  end
  
  class_eval do
    define_method :image_files do
      files
    end
  end
end

.set_js_files(files) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/qedproject/libraries/base.rb', line 26

def set_js_files(files)
  # define class method
  m = class << self; self; end
  m.send :define_method, :js_files do
    files
  end
  
  # define instance method
  class_eval do
    define_method :js_files do
      files
    end
  end
end

Instance Method Details

#copy_cssObject



91
92
93
94
95
# File 'lib/qedproject/libraries/base.rb', line 91

def copy_css
  self.css_files.each do |lib|
    ::FileUtils.cp_r File.join(self.lib_root, lib), File.join(self.project.path, self.project.css_path), :verbose => self.project.verbose
  end
end

#copy_imagesObject



85
86
87
88
89
# File 'lib/qedproject/libraries/base.rb', line 85

def copy_images
  self.image_files.each do |lib|
    ::FileUtils.cp_r File.join(self.lib_root, lib), File.join(self.project.path, self.project.images_path), :verbose => self.project.verbose
  end
end

#copy_jsObject



97
98
99
100
101
# File 'lib/qedproject/libraries/base.rb', line 97

def copy_js
  self.js_files.each do |lib|
    ::FileUtils.cp_r File.join(self.lib_root, lib), File.join(self.project.path, self.project.js_path), :verbose => self.project.verbose
  end
end

#generate!Object



79
80
81
82
83
# File 'lib/qedproject/libraries/base.rb', line 79

def generate!
  self.copy_js     if self.respond_to?(:js_files) && self.js_files.any?
  self.copy_css    if self.respond_to?(:css_files) && self.css_files.any?
  self.copy_images if self.respond_to?(:image_files) && self.image_files.any?
end