Class: Troy::Site
- Inherits:
-
Object
- Object
- Troy::Site
- Defined in:
- lib/troy/site.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
-
#config ⇒ Object
A shortcut to the configuration.
- #export ⇒ Object
- #export_assets ⇒ Object
- #export_files ⇒ Object
- #export_pages(file = nil) ⇒ Object
-
#initialize(root) ⇒ Site
constructor
A new instance of Site.
- #load_configuration ⇒ Object
- #load_extensions ⇒ Object
-
#pages ⇒ Object
Return all pages wrapped in Troy::Page class.
- #remove_public_dir ⇒ Object
- #set_locale ⇒ Object
- #source ⇒ Object
- #uglifier_options ⇒ Object
Constructor Details
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
3 4 5 |
# File 'lib/troy/site.rb', line 3 def root @root end |
Instance Method Details
#config ⇒ Object
A shortcut to the configuration.
116 117 118 |
# File 'lib/troy/site.rb', line 116 def config Troy.configuration end |
#export ⇒ Object
37 38 39 40 41 42 |
# File 'lib/troy/site.rb', line 37 def export remove_public_dir export_assets export_files export_pages end |
#export_assets ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/troy/site.rb', line 75 def export_assets sprockets = Sprockets::Environment.new sprockets.append_path root.join("assets/javascripts") sprockets.append_path root.join("assets/stylesheets") sprockets.css_compressor = Sprockets::SassCompressor if config.assets.compress_css sprockets.js_compressor = Uglifier.new() if config.assets.compress_js config.assets.precompile.each do |asset_name| asset = sprockets[asset_name] output_file = asset.pathname.to_s .gsub(root.join("assets").to_s, "") .gsub(%r[^/], "") .gsub(/\.scss$/, ".css") .gsub(/\.coffee$/, ".js") asset.write_to root.join("public/#{output_file}") end end |
#export_files ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/troy/site.rb', line 46 def export_files assets = root.join("assets") assets.entries.each do |entry| basename = entry.to_s next if [".", "..", "javascripts", "stylesheets"].include?(basename) FileUtils.rm_rf root.join("public/#{basename}") FileUtils.cp_r assets.join(entry), root.join("public/#{basename}") end end |
#export_pages(file = nil) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/troy/site.rb', line 65 def export_pages(file = nil) file = File.(file) if file pages .select {|page| file.nil? || page.path == file } .each(&:save) end |
#load_configuration ⇒ Object
31 32 33 |
# File 'lib/troy/site.rb', line 31 def load_configuration load root.join("config/troy.rb") end |
#load_extensions ⇒ Object
15 16 17 18 19 |
# File 'lib/troy/site.rb', line 15 def load_extensions Dir[root.join("config/**/*helpers.rb")].each do |file| require file end end |
#pages ⇒ Object
Return all pages wrapped in Troy::Page class.
111 112 113 |
# File 'lib/troy/site.rb', line 111 def pages @pages ||= source.map {|path| Page.new(self, path) } end |
#remove_public_dir ⇒ Object
59 60 61 |
# File 'lib/troy/site.rb', line 59 def remove_public_dir FileUtils.rm_rf root.join("public") end |
#set_locale ⇒ Object
23 24 25 26 27 |
# File 'lib/troy/site.rb', line 23 def set_locale I18n.load_path += config.i18n.load_path I18n.default_locale = config.i18n.locale I18n.locale = config.i18n.locale end |
#source ⇒ Object
105 106 107 |
# File 'lib/troy/site.rb', line 105 def source Dir[root.join("source/**/*.{html,erb,md,builder,xml,txt}").to_s] end |
#uglifier_options ⇒ Object
97 98 99 100 101 |
# File 'lib/troy/site.rb', line 97 def = Uglifier::DEFAULTS.dup [:output][:comments] = :none end |