-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Josep M. Bach
committed
Feb 23, 2011
0 parents
commit 65fe690
Showing
16 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
--color | |||
--format documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
rvm --create use ruby-1.9.2@gram |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
source :gemcutter | |||
|
|||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
PATH | |||
remote: . | |||
specs: | |||
gram (0.0.1) | |||
rest-client | |||
|
|||
GEM | |||
remote: http://rubygems.org/ | |||
specs: | |||
diff-lcs (1.1.2) | |||
mime-types (1.16) | |||
rest-client (1.6.1) | |||
mime-types (>= 1.16) | |||
rspec (2.5.0) | |||
rspec-core (~> 2.5.0) | |||
rspec-expectations (~> 2.5.0) | |||
rspec-mocks (~> 2.5.0) | |||
rspec-core (2.5.1) | |||
rspec-expectations (2.5.0) | |||
diff-lcs (~> 1.1.2) | |||
rspec-mocks (2.5.0) | |||
|
|||
PLATFORMS | |||
ruby | |||
|
|||
DEPENDENCIES | |||
bundler (~> 1.0.7) | |||
gram! | |||
rest-client | |||
rspec (~> 2.5.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
require 'rubygems' | |||
require 'rake' | |||
|
|||
require 'rspec/core/rake_task' | |||
desc "Run the specs under spec" | |||
RSpec::Core::RakeTask.new | |||
|
|||
task :default => :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
#gram | |||
|
|||
Gram is an internal administration tool for Codegram. | |||
|
|||
It is composed of independent components. For now the only available component is Blog. To install and setup Gram, just do the following: | |||
|
|||
$ echo "token: MY_CODEGRAM_TOKEN" > ~/.gramrc | |||
$ gem install gram | |||
|
|||
##Blog component | |||
|
|||
To publish a blogpost, type this: | |||
|
|||
$ gram blog my_blogpost.markdown | |||
|
|||
The `my_blogpost.markdown` file should be a regular markdown file with some headers in it, like this: | |||
|
|||
--- | |||
title: My blog post title | |||
tagline: Stranger than fiction | |||
--- | |||
|
|||
# My awesome header | |||
## More markdown goodness, etc. | |||
|
|||
## Copyright | |||
|
|||
Copyright (c) 2011 Codegram. See LICENSE for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
#!/usr/bin/env ruby | |||
$: << 'lib' | |||
require 'gram' | |||
|
|||
component = ARGV.shift | |||
args = ARGV | |||
|
|||
raise "Unknown Gram component. Available components are: #{Gram::COMPONENTS.join(', ')}" unless Gram::COMPONENTS.include?(component) | |||
|
|||
eval("Gram::#{component.capitalize}").run(*args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,26 @@ | |||
# -*- encoding: utf-8 -*- | |||
$:.push File.expand_path("../lib", __FILE__) | |||
require "gram/version" | |||
|
|||
Gem::Specification.new do |s| | |||
s.name = "gram" | |||
s.version = Gram::VERSION | |||
s.platform = Gem::Platform::RUBY | |||
s.authors = ["Josep M. Bach", "Josep Jaume Rey", "Oriol Gual"] | |||
s.email = ["info@codegram.com"] | |||
s.homepage = "http://github.com/codegram/gram" | |||
s.summary = %q{Internal client for Codegram administration} | |||
s.description = %q{Internal client for Codegram administration} | |||
|
|||
s.rubyforge_project = "gram" | |||
|
|||
s.add_runtime_dependency 'rest-client' | |||
|
|||
s.add_development_dependency 'bundler', '~> 1.0.7' | |||
s.add_development_dependency 'rspec', '~> 2.5.0' | |||
|
|||
s.files = `git ls-files`.split("\n") | |||
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"] | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
require 'gram/blog' | |||
require 'gram/blog/parser' | |||
|
|||
module Gram | |||
COMPONENTS = %w(blog) | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
require 'rest-client' | |||
|
|||
module Gram | |||
module Blog | |||
class << self | |||
|
|||
def run(*args) | |||
file = args.first | |||
raise "File #{file} does not exist." unless File.exists?(file) | |||
puts "Gram::Blog posting..." | |||
post = Parser.parse(file) | |||
response = RestClient.post("http://codegram.com/api/posts", token: get_token, post: post ) | |||
puts "Response Code: #{response.code}" | |||
puts "Response Body: #{response.body}" | |||
end | |||
|
|||
private | |||
|
|||
def get_token | |||
if File.exists?(File.join(File.expand_path('~'), '.gramrc')) | |||
YAML.load(File.read(File.join(File.expand_path('~'), '.gramrc')))["token"] | |||
else | |||
puts "Can't get Gram token. Please create a ~/.gramrc YAML file with a token key." | |||
exit(1) | |||
end | |||
end | |||
|
|||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
require 'yaml' | |||
|
|||
module Gram | |||
module Blog | |||
module Parser | |||
class << self | |||
|
|||
def parse(file) | |||
raw_content = File.read(file) | |||
headers = raw_content.match(/---(.*)---/m) | |||
yaml = YAML.load($1.strip) | |||
|
|||
title = yaml["title"] | |||
tagline = yaml["tagline"] | |||
|
|||
content = raw_content.gsub(/---.*---/m, '').strip | |||
|
|||
{ title: title, tagline: tagline, body: content } | |||
end | |||
|
|||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
module Gram | |||
VERSION = '0.0.1' | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
require 'spec_helper' | |||
|
|||
module Gram | |||
module Blog | |||
describe Parser do | |||
|
|||
describe ".parse" do | |||
it 'converts a file into a hash' do | |||
file = double :file | |||
raw = """ | |||
--- | |||
title: My title | |||
tagline: My tagline | |||
--- | |||
#My post | |||
# | |||
Blah | |||
""" | |||
File.stub(:read).with(file).and_return raw | |||
|
|||
subject.parse(file).should == { title: 'My title', | |||
tagline: 'My tagline', | |||
body: "#My post\n#\nBlah"} | |||
end | |||
end | |||
|
|||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
require 'spec_helper' | |||
|
|||
module Gram | |||
describe Blog do | |||
|
|||
describe ".run" do | |||
it 'parses the file' do | |||
subject::Parser.should_receive(:parse).with("my_post.md") | |||
expect { | |||
subject.run("my_post.md") | |||
}.to raise_error(RestClient::InternalServerError) | |||
end | |||
it 'sends a post request' do | |||
post = double :post | |||
token = double :token | |||
response = double :response, code: 201, body: 'ok' | |||
subject.stub(:get_token).and_return token | |||
subject::Parser.stub(:parse).with("my_post.md").and_return post | |||
|
|||
RestClient.should_receive(:post).with("http://codegram.com/api/posts", token: token, post: post).and_return response | |||
|
|||
subject.run("my_post.md") | |||
end | |||
end | |||
|
|||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
require 'spec_helper' | |||
|
|||
describe Gram do | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
require 'rspec' | |||
require 'gram' |