Class: SimpleSite::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_site/site.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Site

Returns a new instance of Site.



6
7
8
9
10
11
12
# File 'lib/simple_site/site.rb', line 6

def initialize(options = {})
  @options = {}
  @options[:buckets] ||= [options.delete(:bucket)].compact
  options[:buckets].each {|bucket| @options[:buckets] << bucket } unless options[:buckets].nil?
  @options.merge!(options)
  @options[:js_files] ||= Dir['_js/*.js']
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/simple_site/site.rb', line 4

def options
  @options
end

Instance Method Details

#bucket=(bucket) ⇒ Object



18
19
20
# File 'lib/simple_site/site.rb', line 18

def bucket=(bucket)
  @options[:buckets] = [bucket]
end

#buckets=(buckets) ⇒ Object



22
23
24
# File 'lib/simple_site/site.rb', line 22

def buckets=(buckets)
  @options[:buckets] = buckets
end

#deploy!Object



49
50
51
52
53
54
# File 'lib/simple_site/site.rb', line 49

def deploy!
  Dir.chdir('public')
  Dir['**/*'].select { |f| File.file?(f) }.each do |file|
    deploy file
  end
end

#deploy_file!Object



56
57
58
59
60
61
# File 'lib/simple_site/site.rb', line 56

def deploy_file!
  Dir.chdir('public')
  ENV['FILES'].split(",").select { |f| File.file?(f) }.each do |file|
    deploy file
  end
end

#generate_cssObject



32
33
34
35
36
# File 'lib/simple_site/site.rb', line 32

def generate_css
  return unless File.exists? '_sass/style.sass'
  system "sass _sass/style.sass public/css/style.css"
  puts "Regenerated css!"
end

#generate_htmlObject



26
27
28
29
30
# File 'lib/simple_site/site.rb', line 26

def generate_html
  engine = Haml::Engine.new(File.read('_src/index.haml'))
  File.open('public/index.html', 'w') {|f| f.write(engine.render(SimpleSite::HamlContext.new)) }
  puts "Regenerated html!"
end

#generate_jsObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/simple_site/site.rb', line 38

def generate_js
  return if @options[:js_files].empty?
  system 'mkdir -p _tmp; touch _tmp/js.js; :> _tmp/js.js'
  @options[:js_files].each do |f|
    system "cat _js/#{f} >> _tmp/js.js"
  end
  File.open('public/js/script.js', 'w') {|f| f.write(Uglifier.compile(File.read('_tmp/js.js'))) }
  system 'rm _tmp/js.js'
  puts "Regenerated js!"
end

#js_files=(files) ⇒ Object



14
15
16
# File 'lib/simple_site/site.rb', line 14

def js_files=(files)
  @options[:js_files] = files
end