Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added generate feature.

  • Loading branch information...
commit 38141549cb5d464ea5f2ba0a6aece148c1262aa3 1 parent 9d6eb71
@jingweno authored
View
4 features/presenter_creates_a_skeletal_installation.feature
@@ -2,11 +2,11 @@ Feature: presenter creates a skeletal installation
Scenario: creates a skeletal installation
Given the jekyll_and_hyde gem installed
- When I run the "jh new test" command
+ When I run the "jh new test" command inside folder "/"
Then I should have a folder named "test" created
And I should have template files/folders "_config.yml, _includes, _layouts, index.html, stylesheets, .git, .gitmodules, slippy" inside folder "test"
Scenario: creates a skeletal installation with GitHub project page branch setup
Given the jekyll_and_hyde gem installed
- When I run the "jh new test --github" command
+ When I run the "jh new test --github" command inside folder "/"
Then I should have a git branch named "gh-pages" created in folder "test"
View
6 features/presenter_creates_slides.feature
@@ -0,0 +1,6 @@
+Feature: presenter creates slides
+
+ Scenario: creates a slide
+ Given I run the "jh new test" command inside folder "/"
+ When I run the "jh generate test-slide" command inside folder "test"
+ Then I should have a file named "test-slide.markdown" prefixed with timestamp created in posts folder "test/_posts"
View
11 features/step_definitions/jekyll_and_hyde_steps.rb
@@ -9,13 +9,13 @@
Given /^the jekyll_and_hyde gem installed$/ do
end
-When /^I run the "jh ([^"]*)" command$/ do |parameters|
+When /^I run the "jh ([^"]*)" command inside folder "([^"]*)"$/ do |parameters, folder|
parameters = parameters.split.map(&:strip)
task = parameters.shift
args, opts = Thor::Options.split(parameters)
@task = JekyllAndHyde::Util.find_task_class(task).new(args, opts)
- @task.destination_root = DESTINATION_ROOT
+ @task.destination_root = File.join(DESTINATION_ROOT, folder)
@task.invoke(JekyllAndHyde.to_namespace(task))
end
@@ -32,4 +32,11 @@
Then /^I should have a git branch named "([^"]*)" created in folder "([^"]*)"$/ do |branch_name, folder_name|
output = IO.popen("cd #{File.join(DESTINATION_ROOT, folder_name)} && git branch")
output.readlines.first.include?(branch_name)
+end
+
+Then /^I should have a file named "([^"]*)" prefixed with timestamp created in posts folder "([^"]*)"$/ do |file_name, folder_name|
+ posts_folder = Dir[File.join(DESTINATION_ROOT, folder_name, "**", "*.*")]
+ posts_folder.should have(1).file
+ post_file_name = posts_folder.first.scan(/\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d-(.*)/).flatten.first
+ post_file_name.should == file_name
end
View
1  lib/jekyll_and_hyde.rb
@@ -12,4 +12,5 @@
require 'jekyll_and_hyde/util'
require 'jekyll_and_hyde/group'
require 'jekyll_and_hyde/tasks/new'
+require 'jekyll_and_hyde/tasks/generate'
require 'jekyll_and_hyde/runner'
View
1  lib/jekyll_and_hyde/runner.rb
@@ -42,7 +42,6 @@ def self.banner(task, all = false, subcommand = false)
# Display information about the given klasses. If with_module is given,
# it shows a table with information extracted from the yaml file.
- #
def display_klasses(klasses=Thor::Base.subclasses)
klasses -= JekyllAndHyde::Group.ancestors
raise Error, "No JekyllAndHyde tasks available" if klasses.empty?
View
17 lib/jekyll_and_hyde/tasks/generate.rb
@@ -0,0 +1,17 @@
+module JekyllAndHyde
+ class Generate < JekyllAndHyde::Group
+ argument :title, :type => :string, :required => true, :desc => "The title of the slide."
+ class_option :format, :type => :string, :default => 'markdown', :desc => 'The format of the slide. It can be "markdown" or "textile".'
+ desc "Generate a slide using the defined template."
+
+ def create_slide
+ create_file File.join("_posts", "#{timestamp}-#{title}.#{options[:format]}")
+ end
+
+ private
+
+ def timestamp
+ Time.now.strftime("%Y-%m-%d-%H-%M-%S")
+ end
+ end
+end
View
22 spec/jekyll_and_hyde/tasks/generate_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+module JekyllAndHyde
+ describe Generate do
+ before(:each) do
+ @generate_task = JekyllAndHyde::Generate.new(["test_slide"], {}, {})
+ end
+
+ describe "#timestamp" do
+ it "should return timestamp separated by '-'" do
+ @generate_task.send(:timestamp).to_s.scan(/\d\d\d\d-\d\d-\d\d-\d\d-\d\d-\d\d/).should_not be_empty
+ end
+ end
+
+ describe "#create_slide" do
+ it "should create a file" do
+ @generate_task.should_receive(:create_file)
+ @generate_task.create_slide
+ end
+ end
+ end
+end
View
33 spec/jekyll_and_hyde/tasks/new_spec.rb
@@ -1,28 +1,23 @@
require 'spec_helper'
-require 'fakefs/spec_helpers'
module JekyllAndHyde
- module Generators
- describe New do
- include FakeFS::SpecHelpers
+ describe New do
+ before(:each) do
+ @new_task = JekyllAndHyde::New.new(["app_path"], {}, {})
+ end
- before(:each) do
- @new_generator = JekyllAndHyde::New.new(["app_path"], {}, {})
- end
-
- describe "#make_app_path_dir" do
- it "should create the given directory" do
- @new_generator.should_receive(:empty_directory).with("app_path")
- @new_generator.make_app_path_dir
- end
+ describe "#make_app_path_dir" do
+ it "should create the given directory" do
+ @new_task.should_receive(:empty_directory).with("app_path")
+ @new_task.make_app_path_dir
end
+ end
- describe "#inside_app_path" do
- it "should have all other operations execute inside app path" do
- %W{git_clone_template git_init add_slippy_git_submodule git_add_all}.each do |method|
- @new_generator.should_receive(:inside_app_path)
- @new_generator.send(method)
- end
+ describe "#inside_app_path" do
+ it "should have all other operations execute inside app path" do
+ %W{git_clone_template git_init add_slippy_git_submodule git_add_all}.each do |method|
+ @new_task.should_receive(:inside_app_path)
+ @new_task.send(method)
end
end
end
View
2  spec/jekyll_and_hyde/util_spec.rb
@@ -3,7 +3,7 @@
module JekyllAndHyde
describe Util do
describe "#find_task_class" do
- it "should create a task if it finds it" do
+ it "should return result for existing task" do
class JekyllAndHyde::TestTask < Thor; end
JekyllAndHyde::Util.find_task_class("test_task").should be
Please sign in to comment.
Something went wrong with that request. Please try again.