Skip to content

Commit

Permalink
0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christiansen committed Dec 11, 2012
1 parent a48666f commit 8e4187c
Show file tree
Hide file tree
Showing 14 changed files with 448 additions and 30 deletions.
16 changes: 12 additions & 4 deletions Gemfile
@@ -1,4 +1,12 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in twitter-bootstrap-calendar.gemspec
gemspec
source "http://rubygems.org"

# Specify your gem's dependencies in twitter-bootstrap-rails.gemspec
gemspec
gem 'less-rails', :path => ENV['LESS_RAILS_SOURCE'] if ENV['LESS_RAILS_SOURCE']

group :test do
gem 'minitest'
gem 'mocha'
gem 'rake'
gem 'turn'
end
15 changes: 14 additions & 1 deletion README.md
Expand Up @@ -8,6 +8,10 @@ Add this line to your application's Gemfile:

gem 'twitter-bootstrap-calendar'

Add this line to your application.css:

*= require twitter-bootstrap-calendar

And then execute:

$ bundle
Expand All @@ -18,7 +22,16 @@ Or install it yourself as:

## Usage

TODO: Write usage instructions here
To create a calendar in your view, just call the helper method and pass in a block, like so:
```haml
= bootstrap_calendar month do |date|
= link_to date.day, new_plan_event_path(:event => {:activity_at => date.beginning_of_day + 12.hours})
- if @events_by_date[date]
ul.event_summary
- @events_by_date[date].each do |event|
li style=event_style(event)
= link_to "#{event.title}: #{event.activity_at.to_s(:time_only)}", menu_plan_event_path(event), :remote => true, :style => event_link_style(event)
```

## Contributing

Expand Down
36 changes: 34 additions & 2 deletions Rakefile
@@ -1,2 +1,34 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
#!/usr/bin/env rake
require 'bundler'
Bundler::GemHelper.install_tasks

desc "Bundle the gem"
task :bundle do
sh('bundle install')
sh 'gem build *.gemspec'
sh 'gem install *.gem'
sh 'rm *.gem'
end

# desc "Build the static precompiled stylesheets from Less sources"
# task :build_static_stylesheets do
# require 'less'

# toolkit_path = File.join('vendor', 'toolkit')

# parser = Less::Parser.new :paths => [toolkit_path]

# target_directory = File.expand_path('vendor/assets/stylesheets/twitter-bootstrap-static')

# sh "rm -rf #{target_directory}"
# sh "mkdir -p #{target_directory}"
# Dir['vendor/static-source/*.less'].each do |source_file|
# puts "Compiling #{source_file}"
# target_file = File.join(target_directory, File.basename(source_file, '.less')+'.css.erb')
# tree = parser.parse(File.read(source_file))
# File.open(target_file, 'w') {|f| f.puts tree.to_css(:compress => true) }
# end
# end

task(:default).clear
task :default => :bundle
64 changes: 64 additions & 0 deletions app/helpers/bootstrap_calendar_helper.rb
@@ -0,0 +1,64 @@
module BootstrapCalendarHelper
def bootstrap_calendar(date = Date.today, &block)
BootstrapCalendar.new(self, date, block).calendar_div
end

BootstrapCalendar = Struct.new(:view, :date, :callback) do
HEADER = %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
START_DAY = :sunday

delegate :content_tag, to: :view

def calendar_div
content_tag 'div', class: "calendar_grid" do
header + week_rows
end
end

def header
content_tag 'div', class: 'month_header row-fluid' do
HEADER.map { |day| content_tag :div, class: 'span1' do
day
end }.join.html_safe
end
end

def week_rows
weeks.map {|week|
content_tag :div, class: 'row-fluid week' do
week.map { |day| day_cell(day) }.join.html_safe
end
}.join.html_safe
end

def day_cell(day)
content_tag :div, view.capture(day, &callback), class: day_classes(day)
end

def day_classes(day)
classes = ['span1']
classes << "today" if day == Date.today
classes << "notmonth" if day.month != date.month
classes << "month" if day.month == date.month
classes.empty? ? nil : classes.join(" ")
end

def weeks
first = date.beginning_of_month.beginning_of_week(START_DAY)
last = date.end_of_month.end_of_week(START_DAY)
(first..last).to_a.in_groups_of(7)
end
end

def event_style(event)
"background-color: #{event.color};"
end

def event_link_style(event)
if %w(white silver yellow lime aqua teal fuchsia).include?(event.color)
"color: black;"
else
"color: white;"
end
end
end
18 changes: 9 additions & 9 deletions lib/twitter-bootstrap-calendar.rb
@@ -1,9 +1,9 @@
require "twitter-bootstrap-calendar/version"

module Twitter
module Bootstrap
module Calendar
# Your code goes here...
end
end
end
module Twitter
module Bootstrap
module Calendar
require 'twitter/bootstrap/calendar/engine' if defined?(Rails)
end
end
end

require 'twitter/bootstrap/calendar/bootstrap' if defined?(Rails)
2 changes: 2 additions & 0 deletions lib/twitter/bootstrap/calendar/bootstrap.rb
@@ -0,0 +1,2 @@
require "twitter/bootstrap/calendar/engine"
require "twitter/bootstrap/calendar/version"
17 changes: 17 additions & 0 deletions lib/twitter/bootstrap/calendar/engine.rb
@@ -0,0 +1,17 @@
require 'rails'

require File.dirname(__FILE__) + '/../../../../app/helpers/bootstrap_calendar_helper.rb'

module Twitter
module Bootstrap
module Calendar
class Engine < ::Rails::Engine
initializer 'twitter-bootstrap-calendar.setup_helpers' do |app|
app.config.to_prepare do
ActionController::Base.send :helper, BootstrapCalendarHelper
end
end
end
end
end
end
File renamed without changes.
8 changes: 8 additions & 0 deletions test/test_helper.rb
@@ -0,0 +1,8 @@
require "bundler/setup"
Bundler.require

require "minitest/autorun"
require "abstract_controller"
require "action_controller"
require "active_support/dependencies"
require "mocha/setup"
37 changes: 23 additions & 14 deletions twitter-bootstrap-calendar.gemspec
@@ -1,17 +1,26 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/twitter-bootstrap-calendar/version', __FILE__)
$:.push File.expand_path("../lib", __FILE__)
require "twitter/bootstrap/calendar/version"

Gem::Specification.new do |gem|
gem.authors = ["David Christiansen"]
gem.email = ["dave@developertown.com"]
gem.description = %q{TODO: Write a gem description}
gem.summary = %q{TODO: Write a gem summary}
gem.homepage = ""
Gem::Specification.new do |s|
s.name = "twitter-bootstrap-calendar"
s.version = Twitter::Bootstrap::Calendar::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["David Christiansen"]
s.email = ["dave@trooptrack.com"]
s.homepage = "https://github.com/davidray/twitter-bootstrap-calendar"
s.summary = %q{Bootstrap based responsive calendar}
s.description = %q{Adds a helper and 7-column grid for creating calendar views}

gem.files = `git ls-files`.split($\)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.name = "twitter-bootstrap-calendar"
gem.require_paths = ["lib"]
gem.version = Twitter::Bootstrap::Calendar::VERSION
s.files = Dir["lib/**/*"] + Dir["vendor/**/*"] + Dir["app/**/*"] + ["Rakefile", "README.md"]
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency 'sass'
s.add_dependency 'railties', '>= 3.1'
s.add_dependency 'actionpack', '>= 3.1'
# s.add_runtime_dependency 'execjs'
s.add_development_dependency 'rails', '>= 3.1'
# s.add_development_dependency 'less'
# s.add_development_dependency 'therubyracer', '0.10.2'
end
Binary file added vendor/.DS_Store
Binary file not shown.
Binary file added vendor/assets/.DS_Store
Binary file not shown.
Binary file not shown.

0 comments on commit 8e4187c

Please sign in to comment.