diff --git a/lib/siteleaf/site.rb b/lib/siteleaf/site.rb index 69f6444..ed2ebd8 100644 --- a/lib/siteleaf/site.rb +++ b/lib/siteleaf/site.rb @@ -3,12 +3,12 @@ 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) @@ -16,60 +16,61 @@ def theme 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('/','_') @@ -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 \ No newline at end of file diff --git a/lib/siteleaf/version.rb b/lib/siteleaf/version.rb index 8886db2..5f048d3 100644 --- a/lib/siteleaf/version.rb +++ b/lib/siteleaf/version.rb @@ -1,3 +1,3 @@ module Siteleaf - VERSION = "1.0.7" + VERSION = "1.0.8" end diff --git a/siteleaf.gemspec b/siteleaf.gemspec index 69c2a17..a1b1855 100644 --- a/siteleaf.gemspec +++ b/siteleaf.gemspec @@ -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($/)