Class: Theme
- Inherits:
-
Object
- Object
- Theme
- Defined in:
- lib/components/jquery-syntax/ext/theme.rb
Instance Attribute Summary collapse
-
#includes ⇒ Object
readonly
Returns the value of attribute includes.
Instance Method Summary collapse
- #includes_for(path, place) ⇒ Object
-
#initialize(dst_dir, root = nil) ⇒ Theme
constructor
A new instance of Theme.
- #load_theme(theme_dir, top = true) ⇒ Object
Constructor Details
Instance Attribute Details
#includes ⇒ Object (readonly)
Returns the value of attribute includes.
14 15 16 |
# File 'lib/components/jquery-syntax/ext/theme.rb', line 14 def includes @includes end |
Instance Method Details
#includes_for(path, place) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/components/jquery-syntax/ext/theme.rb', line 73 def includes_for(path, place) case place when :prepend return @includes when :append if extension = @extends[File.basename(path)] return extension end end return [] end |
#load_theme(theme_dir, top = true) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/components/jquery-syntax/ext/theme.rb', line 16 def load_theme(theme_dir, top = true) theme_dir = File.join(@root, theme_dir) theme_name = File.basename(theme_dir) master = Dir.glob(File.join(theme_dir, "master.{sass,scss}")) if master.size > 0 @includes += master end unless File.directory?(theme_dir) raise StandardError.new("Could not find theme #{theme_dir}!") end $stderr.puts "Loading theme from #{theme_dir}..." theme_config_path = File.join(theme_dir, "_config.yaml") config = {} # Is there a configuration file? if File.exist? theme_config_path config = YAML::load_file(theme_config_path) || {} end # Load any dependencies recursively - if you have bad configuration this might # give you visions of infinity. if config['depends'] @depends += config['depends'] config['depends'].each {|name| load_theme(name, false)} end # Remove any files/directories that have been excluded if config['exclude'] config['exclude'].each do |name| FileUtils.rm_rf(File.join(@destination, name)) end end if config['extends'] config['extends'].each {|name,extension| @extends[name] = extension} end if config['includes'] @includes.concat(config['includes']) end if top # Copy all the theme files $stderr.puts "Copying #{theme_dir + "/*"} to #{@destination.inspect}" theme_files = Dir.glob(File.join(theme_dir, "*")) FileUtils.cp_r(theme_files, @destination) File.open(File.join(@destination, "theme.js"), "w") do |theme_js| theme_js.puts "Syntax.themes[#{theme_name.inspect}] = #{@depends.inspect}" end end end |