Skip to content

Commit

Permalink
Create new git repository
Browse files Browse the repository at this point in the history
  • Loading branch information
creationix committed Jun 25, 2009
1 parent 117df8c commit 2101b05
Show file tree
Hide file tree
Showing 82 changed files with 3,090 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,5 @@
coverage
rdoc
pkg
.bzr
.bzrignore
41 changes: 24 additions & 17 deletions LICENSE
@@ -1,20 +1,27 @@
Copyright (c) 2009 Tim Caswell
Copyright (c) 2009, Tim Caswell
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the Creationix nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6 changes: 5 additions & 1 deletion Rakefile
Expand Up @@ -5,11 +5,15 @@ begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "milk"
gem.summary = %Q{TODO}
gem.summary = %Q{Milk is a rack based content management system built for ease of use and simplicity. Milk tastes great with and without cookies.}
gem.email = "tim@creationix.com"
gem.homepage = "http://github.com/creationix/milk"
gem.authors = ["Tim Caswell"]
gem.rubyforge_project = "milk"
gem.required_ruby_version = '>=1.9'
gem.add_dependency('rack', '>= 1.0.0')
gem.add_dependency('maruku', '>= 0.6.0')
gem.add_dependency('haml', '>= 2.0.9')
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end

Expand Down
22 changes: 22 additions & 0 deletions bin/milk
@@ -0,0 +1,22 @@
#!/usr/bin/env ruby

require 'fileutils'

if ARGV.length != 1
puts "\nMilk site generator\n"
puts "\nUsage:\n\tmilk [target project]\n\n"
exit 1
end

target_path = File.absolute_path(ARGV[0])
if File.directory?(target_path)
puts "\nERROR: there already exists a folder #{target_path}\n"
exit 1
end

puts "\nCreating milk site at #{target_path}\n"
FileUtils.mkdir_p(target_path, :verbose => true)
MILK_ROOT = target_path
require 'milk'
FileUtils.cp_r(Milk::TEMPLATE_DIR+"/.", target_path, :verbose => true)
puts "\nDone!\n\n"
82 changes: 82 additions & 0 deletions lib/milk.rb
@@ -0,0 +1,82 @@
# Autoload some useful libraries
autoload 'Haml', 'haml'
autoload 'Sass', 'sass'
autoload 'Maruku', 'maruku'
autoload 'YAML', 'yaml'
autoload 'FileUtils', 'fileutils'

# Set up our main namespace with autoloaded parts
module Milk
VERSION = '0.0.5'

LIB_DIR = File.dirname(__FILE__)
BIN_DIR ||= File.absolute_path(File.dirname(__FILE__)+"/../../local/bin")
TEMPLATE_DIR = File.absolute_path(LIB_DIR+"/../site_template")
def self.get_milk_root
c = caller(1).collect { |line| line.split(':').first }
c = c.select { |line| line !~ /\/gems\// }
File.absolute_path(File.dirname(c.first))
end
MILK_ROOT ||= get_milk_root
CONFIG_DIR = MILK_ROOT + "/config"

# Load overrides from config file
config_file = CONFIG_DIR+"/config.yaml"
YAML.load(open(CONFIG_DIR+"/config.yaml")).each_pair do |key, value|
eval("#{key} = #{value.inspect}")
end if File.file?(config_file)

# Set defaults otherwise
COMPONENTS_DIR ||= MILK_ROOT + "/design"
PAGES_DIR ||= MILK_ROOT + "/pages"
PUBLIC_DIR ||= MILK_ROOT + "/public"
FIELDS_DIR ||= LIB_DIR + "/milk/fields"

$LOAD_PATH.unshift(LIB_DIR) unless $LOAD_PATH.include?(LIB_DIR)
autoload :Application, "milk/application"
autoload :Component, "milk/component"
autoload :Page, "milk/page"
autoload :Haxe, "milk/haxe"
autoload :Field, "milk/field"
autoload :Fields, "milk/field"

end

# Autoload the components of the user space app into the root namespace for easy use
Dir.glob(Milk::COMPONENTS_DIR + "/*.rb").each do |c|
name = c.split('/').last.gsub(/(.*)\.rb/) { $1 }
class_name = name.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
path = c.gsub(/(.*)\.rb/) { $1 }
autoload class_name.to_sym, path
end

# Include metaid for easy metaclass management
class Object
# The hidden singleton lurks behind everyone
def metaclass; class << self; self; end; end
def meta_eval &blk; metaclass.instance_eval &blk; end

# Adds methods to a metaclass
def meta_def name, &blk
meta_eval { define_method name, &blk }
end

# Defines an instance method within a class
def class_def name, &blk
class_eval { define_method name, &blk }
end
end

# Add ability to get constants from a string name.
# WARNING: this is akin to eval for security concerns.
class String
def constantize
const = Object
self.split("::").each do |part|
const = const.const_get(part)
end
const
end
end


0 comments on commit 2101b05

Please sign in to comment.