Class: JekyllImport::Importers::Behance
- Inherits:
-
JekyllImport::Importer
- Object
- JekyllImport::Importer
- JekyllImport::Importers::Behance
- Defined in:
- lib/jekyll-import/importers/behance.rb
Class Method Summary collapse
-
.process(options) ⇒ Object
Process the import.
- .require_deps ⇒ Object
- .specify_options(c) ⇒ Object
- .validate(options) ⇒ Object
Methods inherited from JekyllImport::Importer
inherited, run, stringify_keys, subclasses
Class Method Details
.process(options) ⇒ Object
Process the import.
user - the behance user to retrieve projects (ID or username) api_token - your developer API Token
Returns nothing.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/jekyll-import/importers/behance.rb', line 33 def self.process() user = .fetch("user") token = .fetch("api_token") client = fetch_behance(token) user_projects = client.user_projects(user) Jekyll.logger.info "#{user_projects.length} project(s) found. Importing now..." user_projects.each do |project| details = client.project(project["id"]) title = project["name"].to_s formatted_date = Time.at(project["published_on"].to_i).to_date.to_s post_name = title.split(%r{ |!|/|:|&|-|$|,}).map do |character| character.downcase unless character.empty? end.compact.join("-") name = "#{formatted_date}-#{post_name}" header = { "layout" => "post", "title" => title, "details" => details, } FileUtils.mkdir_p("_posts") File.open("_posts/#{name}.md", "w") do |f| f.puts header.to_yaml f.puts "---\n\n" f.puts details["description"].to_s end end Jekyll.logger.info "Finished importing." end |
.require_deps ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/jekyll-import/importers/behance.rb', line 6 def self.require_deps JekyllImport.require_with_fallback(%w( fileutils safe_yaml date time behance )) end |
.specify_options(c) ⇒ Object
16 17 18 19 |
# File 'lib/jekyll-import/importers/behance.rb', line 16 def self.(c) c.option "user", "--user NAME", "The username of the account" c.option "api_token", "--api_token TOKEN", "The API access token for the account" end |
.validate(options) ⇒ Object
21 22 23 24 25 |
# File 'lib/jekyll-import/importers/behance.rb', line 21 def self.validate() %w(user api_token).each do |option| abort "Missing mandatory option --#{option}." if [option].nil? end end |