Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port to sinatra #126

Merged
merged 9 commits into from Mar 15, 2015
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion Gemfile
Expand Up @@ -9,7 +9,22 @@ gem 'dm-core', require: true
gem 'dm-do-adapter', require: true
gem 'dm-postgres-adapter', require: true

gem 'slim', require: true
gem 'redcarpet', github: 'vmg/redcarpet'
gem 'rake'
gem 'sass'

gem 'slim', '< 2.0'
gem 'yard', "~> 0.8.6.2"

gem 'activesupport'
gem 'pygments.rb'
gem 'github-markup'

gem "rest"
gem "twitter"

gem 'link_header'
gem 'sprockets'

group :development, :production do
gem 'foreman'
Expand Down
70 changes: 65 additions & 5 deletions Gemfile.lock
@@ -1,3 +1,9 @@
GIT
remote: git://github.com/vmg/redcarpet.git
revision: 38d135c3ee709a2bd793dd4d544c2c71206dd528
specs:
redcarpet (3.2.0)

GEM
remote: https://rubygems.org/
specs:
Expand All @@ -9,6 +15,7 @@ GEM
tzinfo (~> 1.1)
addressable (2.3.6)
arel (5.0.1.20140414130214)
buftok (0.2.0)
cocoapods-core (0.35.0)
activesupport (>= 3.2.15)
fuzzy_match (~> 2.0.4)
Expand All @@ -30,7 +37,10 @@ GEM
dotenv (0.11.1)
dotenv-deployment (~> 0.0.2)
dotenv-deployment (0.0.2)
equalizer (0.0.9)
eventmachine (1.0.3)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
flounder (0.9.7)
arel (~> 5, > 5.0.1)
connection_pool (~> 2)
Expand All @@ -40,45 +50,95 @@ GEM
dotenv (~> 0.11.1)
thor (~> 0.19.1)
fuzzy_match (2.0.4)
github-markup (1.3.3)
hashie (3.3.1)
hike (1.2.3)
http (0.6.3)
http_parser.rb (~> 0.6.0)
http_parser.rb (0.6.0)
i18n (0.7.0)
json (1.8.2)
link_header (0.0.8)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
minitest (5.5.1)
multi_json (1.10.1)
multipart-post (2.0.0)
nap (0.8.0)
naught (1.0.0)
net-http-persistent (2.9.4)
netrc (0.10.3)
pg (0.17.1)
posix-spawn (0.3.10)
pygments.rb (0.6.2)
posix-spawn (~> 0.3.6)
yajl-ruby (~> 1.2.0)
rack (1.5.2)
rack-protection (1.5.3)
rack
rake (10.4.0)
rest (3.0.6)
net-http-persistent (>= 2.9.1)
netrc
sass (3.4.13)
simple_oauth (0.3.1)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
slim (2.0.3)
temple (~> 0.6.6)
tilt (>= 1.3.3, < 2.1)
temple (0.6.8)
slim (1.3.9)
temple (~> 0.6.3)
tilt (~> 1.3, >= 1.3.3)
sprockets (2.12.3)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
temple (0.6.10)
thin (1.6.2)
daemons (>= 1.0.9)
eventmachine (>= 1.0.0)
rack (>= 1.0.0)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
twitter (5.14.0)
addressable (~> 2.3)
buftok (~> 0.2.0)
equalizer (~> 0.0.9)
faraday (~> 0.9.0)
http (~> 0.6.0)
http_parser.rb (~> 0.6.0)
json (~> 1.8)
memoizable (~> 0.4.0)
naught (~> 1.0)
simple_oauth (~> 0.3.0)
tzinfo (1.2.2)
thread_safe (~> 0.1)
yajl-ruby (1.2.1)
yard (0.8.6.2)

PLATFORMS
ruby

DEPENDENCIES
activesupport
cocoapods-core
dm-core
dm-do-adapter
dm-postgres-adapter
flounder
foreman
github-markup
link_header
pygments.rb
rake
redcarpet!
rest
sass
sinatra
slim
slim (< 2.0)
sprockets
thin
twitter
yard (~> 0.8.6.2)
15 changes: 8 additions & 7 deletions README.md
Expand Up @@ -2,18 +2,19 @@

## Setup

Ideally this website should be ran through a sub-folder of [Strata](https://github.com/CocoaPods/Strata).

1. Clone a copy of [Strata](https://github.com/CocoaPods/Strata) and run `rake clone`. Or if you just want this website `rake clone:cocoapods`.
2. Run `rake db:migrate` to update the database to the latest version.
3. Add a `.env` file with ENVIRONMENT variables, see `sample.env`.
2. Run `rake db:migrate` in Strata to update the database to the latest version.
3. Add a `.env` file with in CocoaPods.org ENVIRONMENT variables, see `sample.env`.

## Running

1. `bundle exec foreman start`

## What is this app?
The server will run on http://localhost:3000

Right now it is a hybrid of a Sinatra app ( see `app.rb` ) and a static Middleman app. Pod pages, and anything database-dependant are ran from the above command. Things like the index, or the about page are generated from inside the middleman folder. To update those:
## Things to note

1. Update the files in `/middleman/source`.
2. Run `bundle exec middleman build` in `/middleman`.
3. Commit changes.
* Large scale design changes should be discussed in a [new issue](https://github.com/cocoapods/cocoapods.org/issues/new) first.
* By default the server will use the production search database in a development environment.
135 changes: 131 additions & 4 deletions Rakefile
@@ -1,12 +1,18 @@
require 'json'
require 'yaml'
require 'twitter'
require 'rest'
require 'link_header'

desc "Initializes your working copy to have the correct submodules and gems"
task :bootstrap do
puts "Updating submodules..."
`git submodule update --init --recursive`

puts "Installing gems"
`bundle install`
Bundler.with_clean_env do

Bundler.with_clean_env do
sh "cd middleman && bundle install"
end
end
Expand All @@ -28,7 +34,7 @@ end

desc "Deploy to staging"
task :deploy_staging do
Bundler.with_clean_env do
Bundler.with_clean_env do
sh "cd middleman && bundle exec middleman build"
sh "cd .."
sh "git add ."
Expand All @@ -40,7 +46,7 @@ end

desc "Deploy current dev database"
task :deploy_staging_db do
Bundler.with_clean_env do
Bundler.with_clean_env do
sh "cd middleman && bundle exec middleman build"
sh "cd .."
sh "git add ."
Expand All @@ -51,3 +57,124 @@ task :deploy_staging_db do
end
end


desc "Generate dev team and contributor infos for the about page."
task :generate do
puts("Generating dev team from Twitter")
Rake::Task["generate_team"].invoke

puts("Generating contributors from Github")
Rake::Task["generate_contributors"].invoke
end

task :generate_team do

# This is for an account @123123wqeqweqqwe
# so I'm not worried if people try break in.

# Think this is rate limited to 15 calls every 15 minutes
# so don't generate twice in a row ;)

client = Twitter::REST::Client.new do |config|
config.consumer_key = "1QaLPhCqKhOeji8WW7Rgrg"
config.consumer_secret = "dvnLGIP7rOMlM4FkLYECY08VPT0L6afsZTjhEfcw"
config.access_token = "2232249636-4bqvbKfGwBsEsU78vSvnpk1JA6Zs8RKRtP466CF"
config.access_token_secret = "jcjML9tG93Nh76IyxzesejOXIostnbfri7iyDPlk6hCU5"
end

["team", "alumni"].each do |team_name|
yaml_data = []

team = YAML.load_file("data/raw_" + team_name + '.yaml')
team.each do |member|
next if member["twitter_username"] == "andyrmyers"
puts("Getting #{ member["twitter_username"] }")

twitter_user = client.user member["twitter_username"]
member["twitter_profile_url"] = twitter_user.profile_image_uri_https.to_s.gsub("_normal", "")
member["twitter_banner_url"] = twitter_user.profile_banner_uri.to_s

yaml_data << member
end

if team_name == "alumni"
yaml_data << {
"name" => "Andy Myers",
"cocoapods_bio" => "Really doing the design.",
"twitter_profile_url" => "https://pbs.twimg.com/profile_images/415145378627862528/TDAPjav-.jpeg",
"twitter_banner_url" => "http://pbs.twimg.com/profile_banners/15503664/1387813885/web"
}
end

File.open("data/#{ team_name }.yaml", "w") do |out|
YAML.dump(yaml_data, out)
end

end
end

task :generate_contributors do
class Commiter
attr_accessor :commits, :avatar_url, :name
def to_hash
Hash[instance_variables.map { |var| [var[1..-1].to_sym, instance_variable_get(var)] }]
end
end

def download_list(url)
# Downloads a list of objects from the URL using `Link` header to paginate
response = RestClient.get(url)
return [] if response.code == 204
items = JSON.parse(response.body)

if response.headers[:link]
link_header = LinkHeader.parse(response.headers[:link])
next_url = link_header.find_link(['rel', 'next'])
items += download_list(next_url.href) if next_url
end

items
end

params = "?client_id=927bff412ce93e98de3e&client_secret=6cb0186380b3b3301709345593a5580aadbf636f"
repos = download_list('https://api.github.com/orgs/CocoaPods/repos' + params)
all_contributors = []

# loop through all projects getting a list of contributors
repos.each do |repo|
project = repo["name"]
next if project == "Specs"

puts "Getting #{project}"

# grab the stats
contributors = download_list("https://api.github.com/repos/CocoaPods/#{project}/contributors" + params)

puts "- Found " + contributors.count.to_s + " contributors."

contributors.each do |contributor|
name = contributor['login']
existing = all_contributors.detect { |e| e.name == name }

if existing
existing.commits += contributor['contributions']
else
commiter = Commiter.new
commiter.name = name
commiter.commits = contributor['contributions']
commiter.avatar_url = contributor['avatar_url']
all_contributors << commiter
end
end

# double check uniques, and order
contributors = all_contributors.uniq { |hash| hash.name }.sort_by { |hash| [-hash.commits, hash.name.downcase] }

# save as hashes for ease of use in middleman
contributors = contributors.map { |s| s.to_hash }

File.open("data/contributors.yaml", "w") do |out|
YAML.dump(contributors, out)
end
end
end