diff --git a/VERSION b/VERSION new file mode 100644 index 000000000..8acdd82b7 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.1 diff --git a/bin/build b/bin/build new file mode 100755 index 000000000..95847ea1e --- /dev/null +++ b/bin/build @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +DESTINATION=${1:-/Volumes/share/chowdown} +BASEURL=${2:-http://chowdown.local} +BRANCH=$(git branch --show-current) + +if ! [ -d "$DESTINATION" ]; then + echo "Destination does not exist: $DESTINATION" + exit 1 +fi + +echo "Building site ($BRANCH) to $DESTINATION" +echo "URL will be $BASEURL" + +# echo "Go ahead with build?" +# select yn in "Yes" "No"; do +# case $yn in +# Yes ) echo "Ok."; break;; +# No ) echo "Exiting."; exit;; +# esac +# done + +echo "Incremental or full?" +select choice in "Incremental" "Full" "Quit"; do + case $choice in + Incremental ) INCREMENTAL="--incremental"; break;; + Full ) INCREMENTAL=""; break;; + Quit ) echo "Exiting."; exit;; + esac +done + +jekyll build -d $DESTINATION -b $BASEURL --trace $INCREMENTAL diff --git a/bin/chowdown b/bin/chowdown new file mode 100755 index 000000000..856ac4d74 --- /dev/null +++ b/bin/chowdown @@ -0,0 +1,142 @@ +#!/usr/bin/env ruby + +require 'pathname' +VERSION = Pathname(__FILE__).join('../../VERSION').read + +class Options + attr_reader :action, :target, :name + + def initialize(action, target, name) + @action = action + @target = target + @name = name + end + + def self.parse(opts) + available_actions = { new: 'build', delete: 'destroy' } + available_targets = REGISTRY.keys + + action = available_actions.fetch(opts.shift.to_sym) + target = opts.shift.to_sym + target = available_targets.include?(target) ? target : nil + name = opts.shift || 'Example' + self.new(action, target, name) + rescue => e + self.show_usage + end + + def self.show_usage + puts "Chowdown v#{VERSION}" + puts "Usage:" + puts " #{Pathname(__FILE__).basename} ACTION PAGE NAME" + puts " ACTION is one of: new, delete" + puts " PAGE is one of: #{REGISTRY.keys.join(', ')}" + puts " NAME is the title of the page you are creating." + puts " eg:\n #{Pathname(__FILE__).basename} new recipe \"Grandma's Cookies\"" + end +end + +class Chowdown + def self.execute(opts) + return if opts.nil? + @target = opts.target + # puts opts.inspect + puts "Chowdown v#{VERSION}" + template + .new(opts.name) + .send(opts.action) + end + + def self.template + Template.lookup(@target) + end +end + +class Template + @@template = 'template.template' + + def initialize(title) + @title = title + end + + def targetpath + @targetpath ||= Pathname('.') + end + + def filename + Pathname( + @title.gsub(/[[:space:]]/, '-') + .gsub(/[^[:alnum:]-]/, '') + .downcase + '.md' + ) + end + + def file_exists? + target_file.exist? + end + + def target_file + targetpath.join(filename) + end + + def template_path + Pathname('./bin').join(@@template) + end + + def build + new_contents = template_path.read + new_contents['{TITLE}'] = @title + new_contents['{IMAGENAME}'] = filename.sub_ext('.jpg').to_s + + if target_file.exist? + puts "That one already exists, try another name." + puts "Tried to create: #{target_file}" + else + target_file.open('w+') {|file| file.write(new_contents) } + + puts "Created: #{target_file}\n Use the same naming structure for any images.\n eg: 'images/#{filename.basename.sub_ext('.jpg')}'" + end + end + + def destroy + if target_file.exist? + target_file.delete + puts "Deleting: #{target_file}" + else + puts "Can't delete: #{target_file}\nIt does not exist." + end + end + + def method_missing(m, *args, &block) + puts ['* method:', m, args] + Options.show_usage + end + + def self.register(name, klass) + REGISTRY[name] = klass + end + def self.lookup(name) + REGISTRY[name.to_s.to_sym] + end +end + +# NullTemplate +class NullTemplate < Template; end + +REGISTRY = Hash.new(NullTemplate) + +# Recipe template +class Recipe < Template + @@template = 'recipe.template' + + def targetpath + @targetpath ||= Pathname('_recipes') + end +end +Template.register(:recipe, Recipe) + + + +# Load the options and execute +options = Options.parse(ARGV) +Chowdown.execute(options) diff --git a/bin/recipe.template b/bin/recipe.template new file mode 100644 index 000000000..08f0e7e1c --- /dev/null +++ b/bin/recipe.template @@ -0,0 +1,43 @@ +--- +layout: recipe +title: {TITLE} +image: {IMAGENAME} +# imagecredit: +# courses: [appetiser, entree, breakfast, snack, lunch, tiffin, dinner, supper] +# cuisines: [Mediterranean, Irish, British, Mexican, French] +# diets: [Diabetic, GlutenFree, Halal, Hindu, Kosher, LowCalorie, LowFat, LowLactose, LowSalt, Vegan, Vegetarian] +# yield: 4 slices +published: true + +ingredients: + - Sugar and spice + - Slugs, snails + - Puppy dog tails + +directions: + - Run **bin/chowdown** command to create new **recipes**. + - Edit this file to reflect your lovely new recipe. + - Copy your images to the **images** folder. If you don't have any yet just comment out the image line above. + +--- +This is an example recipe which should contain the full gamut of options +available. This text is for the freeform description of your recipe. + +Most things conform to the [Recipe schema](https://schema.org/Recipe). Here are some useful shortcuts: + +### Courses + +Refer to the [type of meal](https://schema.org/recipeCategory). + + +### Cuisines + +Which [cuisine](https://schema.org/recipeCuisine) does this recipe belong to? + +### Diets + +Diets is a restricted vocabulary and can only be from the [options listed here](https://schema.org/RestrictedDiet#enumbers), choose all that are appropriate. + +### Tags + +Can be anything else you think is relevant to your recipe. You might tag all the ones that you make in the liquidiser with **`blender`** or perhaps all your chicken wing recipes should be tagged with **`barbecue`**.