lib/siteleaf/site.rb in siteleaf-1.0.0 vs lib/siteleaf/site.rb in siteleaf-1.0.1

- old
+ new

@@ -1,9 +1,9 @@ module Siteleaf class Site < Entity - attr_accessor :title, :domain, :timezone, :meta, :posts_path + 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 @@ -51,25 +51,27 @@ def filename "_config.yml" end - def to_file - assets = Dir.glob("export/_uploads/**/*").each_with_object({}) { |var, hash| hash[var.sub('export/_uploads','/assets')] = var.sub('export/_uploads','/uploads') } + def to_file(dir = 'export') + 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.gsub(Regexp.union(assets.keys), assets) end protected def config attrs = {} attrs['title'] = title attrs['url'] = "http://#{domain}" - - meta.each{|m| attrs[m['key']] = m['value'].to_s.gsub("\r\n","\n")} unless meta.nil? - attrs['timezone'] = timezone attrs['permalink'] = 'pretty' + + meta.each{|m| attrs[m['key']] = m['value'].to_s.gsub("\r\n","\n")} unless meta.nil? # output uploads using v1 /assets path attrs['collections'] = { 'uploads' => { 'title' => 'Uploads', \ No newline at end of file