0

I've installed Jekyll and I'm trying to import a simple CSV file with a few posts. I've never used Ruby before. In Jekyll's import docs it shows the following code that needs to be run via Command Line.

http://import.jekyllrb.com/docs/csv/

$ ruby -rubygems -e 'require "jekyll-import";
JekyllImport::Importers::CSV.run({
  "file" => "my_posts.csv"
})'

I'm I supposed to type the whole thing into Command Line and run it or is the first line supposed to call a function that includes the last three lines of code?

Sorry for the noob question but I really couldn't find any answers to this.

Thanks

3 Answers 3

3

You can put scripts in a file with a .rb extension and run it with:

ruby import_csv.rb

Your file import_csv.rb would contain:

#!/usr/bin/env ruby

require "jekyll-import";
JekyllImport::Importers::CSV.run({
  "file" => "my_posts.csv"
})

I think the -rubygems switch is not needed since it is enabled by default. If not, add the line require rubygems before the other require line.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the reply, I'm now trying to install the gem 'jekyll-import' with gem install jekyll-import but it's taking forever and no response from CLI. Is this normal that there's no reaction at all?
The gem install can be slow sometimes, but should not take minutes. Try running the same command again until it does something useful.
I'm running on OS Mavericks but from the docs it seems Ruby is already installed. I haven't installed anything else such as Macports or Homebrew. Do you think I'm missing something?
Sorry, I have no experience with setting up Ruby on a Mac.
2

Just put your codes in a file with rb extension, it should be something like this,

require 'rubygems'
require "jekyll-import"
JekyllImport::Importers::CSV.run({
  "file" => "my_posts.csv"
})

Lets say file name sample.rb. Then run this file using the following command,

ruby sample.rb

Comments

1

Use IRB console by typing irb at command prompt

2 Comments

So does this mean I type each line one after the other into command line and then press enter to execute the script?
Yes, it does. IRB is a really handle tool for quick stuff like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.