From 877bec67fa5f03916028a317a2a8ab1a95fb0489 Mon Sep 17 00:00:00 2001 From: LightGuard Date: Fri, 17 May 2013 17:29:14 -0600 Subject: [PATCH] Finishing awestruct init * Adding .gitignore * Adding Gemfile and Gemfile.lock * Adding a Rakefile --- .gitignore | 4 ++ Gemfile | 5 ++ Gemfile.lock | 49 +++++++++++++ Rakefile | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 252 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Rakefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2bbf373 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.awestruct +.bundle +_site +.sass-cache diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..f7b14b8 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +# A sample Gemfile +source "https://rubygems.org" + +gem 'awestruct', '~> 0.5.1' +gem 'haml', '~> 4.0.2' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..86c375f --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,49 @@ +GEM + remote: https://rubygems.org/ + specs: + awestruct (0.5.1) + bootstrap-sass (~> 2.3.1.0) + compass (~> 0.12.1) + compass-960-plugin (~> 0.10.4) + git (~> 1.2.5) + haml (~> 4.0.1) + json (~> 1.7.7) + listen (~> 0.7.3) + nokogiri (~> 1.5.6) + rack (~> 1.5.2) + rest-client (~> 1.6.7) + ruby-s3cmd (~> 0.1.5) + tilt (~> 1.3.6) + zurb-foundation (~> 4.0.9) + bootstrap-sass (2.3.1.0) + sass (~> 3.2) + chunky_png (1.2.8) + compass (0.12.2) + chunky_png (~> 1.2) + fssm (>= 0.2.7) + sass (~> 3.1) + compass-960-plugin (0.10.4) + compass (>= 0.10.0) + fssm (0.2.10) + git (1.2.5) + haml (4.0.2) + tilt + json (1.7.7) + listen (0.7.3) + mime-types (1.23) + nokogiri (1.5.9) + rack (1.5.2) + rest-client (1.6.7) + mime-types (>= 1.16) + ruby-s3cmd (0.1.5) + sass (3.2.9) + tilt (1.3.7) + zurb-foundation (4.0.9) + sass (>= 3.2.0) + +PLATFORMS + ruby + +DEPENDENCIES + awestruct (~> 0.5.1) + haml (~> 4.0.2) diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..459b225 --- /dev/null +++ b/Rakefile @@ -0,0 +1,194 @@ +# This file is a rake build file. The purpose of this file is to simplify +# setting up and using Awestruct. It's not required to use Awestruct, though it +# does save you time (hopefully). If you don't want to use rake, just ignore or +# delete this file. +# +# If you're just getting started, execute this command to install Awestruct and +# the libraries on which it depends: +# +# rake setup +# +# The setup task installs the necessary libraries according to which Ruby +# environment you are using. If you want the libraries kept inside the project, +# execute this command instead: +# +# rake setup[local] +# +# IMPORTANT: To install gems, you'll need development tools on your machine, +# which include a C compiler, the Ruby development libraries and some other +# development libraries as well. +# +# There are also tasks for running Awestruct. The build will auto-detect +# whether you are using Bundler and, if you are, wrap calls to awestruct in +# `bundle exec`. +# +# To run in Awestruct in development mode, execute: +# +# rake +# +# To clean the generated site before you build, execute: +# +# rake clean preview +# +# To deploy using the production profile, execute: +# +# rake deploy +# +# To get a list of all tasks, execute: +# +# rake -T +# +# Now you're Awestruct with rake! + +$use_bundle_exec = true +$install_gems = ['awestruct -v "~> 0.5.0"', 'rb-inotify -v "~> 0.9.0"'] +$awestruct_cmd = nil +task :default => :preview + +desc 'Setup the environment to run Awestruct' +task :setup, [:env] => :init do |task, args| + next if !which('awestruct').nil? + + if File.exist? 'Gemfile' + if args[:env] == 'local' + require 'fileutils' + FileUtils.remove_file 'Gemfile.lock', true + FileUtils.remove_dir '.bundle', true + system 'bundle install --binstubs=_bin --path=.bundle' + else + system 'bundle install' + end + else + if args[:env] == 'local' + $install_gems.each do |gem| + msg "Installing #{gem}..." + system "gem install --bindir=_bin --install-dir=.bundle #{gem}" + end + else + $install_gems.each do |gem| + msg "Installing #{gem}..." + system "gem install #{gem}" + end + end + end + msg 'Run awestruct using `awestruct` or `rake`' + # Don't execute any more tasks, need to reset env + exit 0 +end + +desc 'Update the environment to run Awestruct' +task :update => :init do + if File.exist? 'Gemfile' + system 'bundle update' + else + system 'gem update awestruct' + end + # Don't execute any more tasks, need to reset env + exit 0 +end + +desc 'Build and preview the site locally in development mode' +task :preview => :check do + run_awestruct '-d' +end + +desc 'Generate the site using the development profile' +task :gen => :check do + run_awestruct '-P development -g --force' +end + +desc 'Generate the site and deploy to production' +task :deploy => :check do + run_awestruct '-P production -g --force --deploy' +end + +desc 'Clean out generated site and temporary files' +task :clean, :spec do |task, args| + require 'fileutils' + dirs = ['.awestruct', '.sass-cache', '_site'] + if args[:spec] == 'all' + dirs << '_tmp' + end + dirs.each do |dir| + FileUtils.remove_dir dir unless !File.directory? dir + end +end + +# Perform initialization steps, such as setting up the PATH +task :init do + # Detect using gems local to project + if File.exist? '_bin' + ENV['PATH'] = "_bin#{File::PATH_SEPARATOR}#{ENV['PATH']}" + ENV['GEM_HOME'] = '.bundle' + end +end + +desc 'Check to ensure the environment is properly configured' +task :check => :init do + if !File.exist? 'Gemfile' + if which('awestruct').nil? + msg 'Could not find awestruct.', :warn + msg 'Run `rake setup` or `rake setup[local]` to install from RubyGems.' + # Enable once the rubygem-awestruct RPM is available + #msg 'Run `sudo yum install rubygem-awestruct` to install via RPM. (Fedora >= 18)' + exit 1 + else + $use_bundle_exec = false + next + end + end + + begin + require 'bundler' + Bundler.setup + rescue LoadError + $use_bundle_exec = false + rescue StandardError => e + msg e.message, :warn + if which('awestruct').nil? + msg 'Run `rake setup` or `rake setup[local]` to install required gems from RubyGems.' + else + msg 'Run `rake update` to install additional required gems from RubyGems.' + end + exit e.status_code + end +end + +# Execute Awestruct +def run_awestruct(args) + system "#{$use_bundle_exec ? 'bundle exec ' : ''}awestruct #{args}" +end + +# A cross-platform means of finding an executable in the $PATH. +# Respects $PATHEXT, which lists valid file extensions for executables on Windows +# +# which 'awestruct' +# => /usr/bin/awestruct +def which(cmd, opts = {}) + unless $awestruct_cmd.nil? || opts[:clear_cache] + return $awestruct_cmd + end + + $awestruct_cmd = nil + exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] + ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| + exts.each do |ext| + candidate = File.join path, "#{cmd}#{ext}" + if File.executable? candidate + $awestruct_cmd = candidate + return $awestruct_cmd + end + end + end + return $awestruct_cmd +end + +# Print a message to STDOUT +def msg(text, level = :info) + case level + when :warn + puts "\e[31m#{text}\e[0m" + else + puts "\e[33m#{text}\e[0m" + end +end