Sha256: 3eef3c69e0504cc55529e095c69f77e98999dc8320f3e1229e371a6b2b79d0df

Contents?: true

Size: 1.83 KB

Versions: 5

Compression:

Stored size: 1.83 KB

Contents

module Troy
  class Site
    attr_accessor :root

    def initialize(root)
      @root = Pathname.new(root).realpath

      load_configuration
      load_extensions
      set_locale
    end

    #
    #
    def load_extensions
      Dir[root.join("config/**/*helpers.rb")].each do |file|
        require file
      end
    end

    #
    #
    def set_locale
      I18n.load_path += Troy.configuration.i18n.load_path
      I18n.locale = Troy.configuration.i18n.locale
    end

    #
    #
    def load_configuration
      load root.join("config/troy.rb")
    end

    #
    #
    def export
      remove_public_dir
      export_assets
      export_pages
      copy_images
    end

    #
    #
    def copy_images
      FileUtils.cp_r(root.join("assets/images"), root.join("public/images"))
    end

    #
    #
    def remove_public_dir
      FileUtils.rm_rf(root.join("public"))
    end

    #
    #
    def export_pages
      pages.each(&:save)
    end

    #
    #
    def copy_assets
      FileUtils.cp_r(root.join("assets"), root.join("public"))
    end

    #
    #
    def export_assets
      sprockets = Sprockets::Environment.new
      sprockets.append_path root.join("assets/javascripts")
      sprockets.append_path root.join("assets/stylesheets")

      Troy.configuration.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

    #
    #
    def source
      Dir[root.join("source/**/*.{html,erb,md,builder,xml}").to_s]
    end

    # Return all pages wrapped in Troy::Page class.
    #
    def pages
      @pages ||= source.map {|path| Page.new(self, path) }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
troy-0.0.5 lib/troy/site.rb
troy-0.0.4 lib/troy/site.rb
troy-0.0.3 lib/troy/site.rb
troy-0.0.2 lib/troy/site.rb
troy-0.0.1 lib/troy/site.rb