Skip to content

Commit

Permalink
export v1 sites with kramdown by default; bump psych and version
Browse files Browse the repository at this point in the history
  • Loading branch information
sskylar committed Oct 11, 2016
1 parent 0765705 commit a20185a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
55 changes: 25 additions & 30 deletions lib/siteleaf/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,74 @@ class Site < Entity

attr_accessor :title, :domain, :timezone, :meta, :posts_path, :version
attr_reader :id, :user_id, :created_at, :updated_at

def self.find_by_domain(domain)
result = Client.get self.endpoint, {"domain" => domain}
self.new(result.first) if result and result.size >= 1
end

def theme
@theme ||= if result = Client.get("sites/#{self.id}/theme")
theme = Theme.new(result)
theme.site_id = self.id
theme
end
end

def assets
result = Client.get "sites/#{self.id}/assets"
result.map { |r| Asset.new(r) } if result
end

def pages
result = Client.get "sites/#{self.id}/pages"
result.map { |r| Page.new(r) } if result
end

def posts
result = Client.get "sites/#{self.id}/posts"
result.map { |r| Post.new(r) } if result
end

def resolve(url = '/')
Client.get "sites/#{self.id}/resolve", {"url" => url}
end

def preview(url = '/', template = nil)
Client.post "sites/#{self.id}/preview", {"url" => url, "template" => template}
end

def publish
result = Client.post "sites/#{self.id}/publish", {}
Job.new(id: result.parsed_response["job_id"]) if result
end

def posts_path
@posts_path || 'posts'
end

def filename
"_config.yml"
end

def config
attrs = {}
attrs['title'] = title
attrs['url'] = "http://#{domain}"
attrs['timezone'] = timezone
attrs['permalink'] = 'pretty'

attrs['markdown'] = 'kramdown'

meta.each{|m| attrs[m['key'].to_s.downcase] = m['value'].to_s == '' ? nil : m['value'].to_s.gsub("\r\n","\n")} unless meta.nil?

# output uploads using v1 /assets path
attrs['collections'] = {
'uploads' => {
'title' => 'Uploads',
'title' => 'Uploads',
'output' => true
}
}

# use collections for any set of posts not called "posts"
pages.each do |page|
path = page.url.sub('/','').gsub('/','_')
Expand All @@ -79,35 +80,29 @@ def config
attrs['collections'][path]['permalink'] = "#{page.url}/:path" if path != page.slug
end
end

# set permalink style for posts
attrs['defaults'] = [{
'scope' => {
'path' => '',
'path' => '',
'type' => 'posts'
},
},
'values' => {
'permalink' => "/#{posts_path}/:title/"
'permalink' => "/#{posts_path}/:title/"
}
}]

# markdown defaults to match v1 rendering
attrs['markdown'] = 'redcarpet'
attrs['redcarpet'] = {
'extensions' => ['autolink', 'fenced_code_blocks', 'lax_spacing', 'strikethrough', 'superscript', 'tables', 'footnotes', 'highlight']
}


attrs
end

def to_file(dir = 'export')
assets = Dir.glob("#{dir}/_uploads/**/*").each_with_object({}) do |var, hash|
assets = Dir.glob("#{dir}/_uploads/**/*").each_with_object({}) do |var, hash|
# remap assets to _uploads
hash[var.sub("#{dir}/_uploads",'/assets')] = var.sub("#{dir}/_uploads",'/uploads')
end

config.to_yaml.gsub(Regexp.union(assets.keys), assets)
end

end
end
2 changes: 1 addition & 1 deletion lib/siteleaf/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Siteleaf
VERSION = "1.0.7"
VERSION = "1.0.8"
end
6 changes: 3 additions & 3 deletions siteleaf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Gem::Specification.new do |gem|
gem.description = %q{A Ruby interface and command line utility for the Siteleaf API.}
gem.summary = "Siteleaf Ruby interface"
gem.homepage = "http://siteleaf.com"

gem.required_ruby_version = '>= 1.9.3'

gem.add_dependency 'httparty', '>= 0.13.3'
gem.add_dependency 'httmultiparty', '>= 0.3.13'
gem.add_dependency 'psych', '2.0.8'
gem.add_dependency 'psych', '>= 2.0.17'
gem.add_dependency 'rack'

gem.files = `git ls-files`.split($/)
Expand Down

0 comments on commit a20185a

Please sign in to comment.