siteleaf 0.8.3 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -19,27 +19,27 @@ The Siteleaf gem is available for installation on [Rubygems](https://rubygems.or
19
19
  Testing sites locally
20
20
  ---------------------
21
21
 
22
- The Siteleaf gem allows you to test and develop your sites locally.
22
+ The Siteleaf gem allows you to test and develop your sites locally. If using [Pow](http://pow.cx) or [Anvil](http://anvilformac.com), your local website will be automatically set up and can be accessed at `http://yoursite.dev`.
23
+
24
+ **(Optional) Install Pow for extra goodness:**
25
+
26
+ curl get.pow.cx | sh
23
27
 
24
28
  **Set up a new site locally:**
25
29
 
26
30
  siteleaf new yoursite.com
27
31
 
28
- This will create a new theme folder in the directory where you ran this command. It will also create the site for you in your Siteleaf account.
32
+ This will create a new theme folder called `yoursite.com` in the directory where you ran this command. It will also create the site for you in your Siteleaf account. If you prefer not to create a new directory, run `siteleaf new yoursite.com .` instead.
29
33
 
30
34
  **Configure an existing site:**
31
35
 
32
36
  siteleaf config yoursite.com
33
37
 
34
- **(Optional) Install Pow for extra goodness:**
38
+ Your site should now be accessible at `http://yoursite.dev`.
35
39
 
36
- If using [Pow](http://pow.cx), your local website will be automatically set up and can be accessed at `http://yoursite.dev`.
40
+ *or*
37
41
 
38
- If you don't have Pow (or Anvil) installed, run:
39
-
40
- curl get.pow.cx | sh
41
-
42
- **Or if you don't want to install Pow, local sites can also be manually run:**
42
+ **If you don't want to install Pow, local sites can also be manually run:**
43
43
 
44
44
  siteleaf server
45
45
 
@@ -49,6 +49,8 @@ In this case, your local site can be accessed at `http://localhost:9292`.
49
49
 
50
50
  Your local folder should contain at least one template file (`default.html`), for sample themes and documentation see: https://github.com/siteleaf/siteleaf-themes
51
51
 
52
+ For new sites, you will also need to create at least one page or post on https://manage.siteleaf.com in order to preview.
53
+
52
54
 
53
55
  Using this gem in your application
54
56
  ----------------------------------
@@ -108,9 +110,10 @@ page = Siteleaf::Page.create({
108
110
  # get page by id
109
111
  page = Siteleaf::Page.find('519719ddcc85910626000001')
110
112
 
111
- # update page, add metadata
113
+ # update page, add metadata, add taxonomy
112
114
  page.title = 'New Title'
113
- page.meta = [{"key" => "foo", "value" => "bar"}]
115
+ page.meta = [ {"key" => "foo", "value" => "bar"} ]
116
+ post.taxonomy = [ {"key" => "Tags", "values" => ["One","Two","Three"]} ]
114
117
  page.save
115
118
 
116
119
  # delete page
data/bin/siteleaf CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'siteleaf'
4
+ require 'fileutils'
4
5
 
5
6
  def help
6
7
  'See https://github.com/siteleaf/siteleaf-gem for documentation.'
@@ -18,7 +19,7 @@ def auth(re_auth = false)
18
19
  password = $stdin.gets.chomp
19
20
  system 'stty echo'
20
21
 
21
- puts "Authorizing..."
22
+ puts "\nAuthorizing..."
22
23
 
23
24
  if auth = Siteleaf::Client.auth(email, password) and auth.is_a?(Hash) and auth.has_key?('api_key')
24
25
  File.open(Siteleaf.settings_file,'w') do|file|
@@ -38,12 +39,12 @@ def config(site)
38
39
  require 'siteleaf'
39
40
  run Siteleaf::Server.new(:site_id => '#{site.id}')" }
40
41
 
41
- pow_path = "#{Etc.getpwuid.dir}/.pow"
42
+ pow_path = File.expand_path('~/.pow')
42
43
  if File.directory?(pow_path)
43
44
  site_no_tld = site.domain.gsub(/\.[a-z]{0,4}$/i,'')
44
45
  site_symlink = "#{pow_path}/#{site_no_tld}"
45
46
  FileUtils.rm(site_symlink) if File.symlink?(site_symlink)
46
- FileUtils.symlink(File.dirname(__FILE__), site_symlink)
47
+ FileUtils.symlink(File.expand_path('.'), site_symlink)
47
48
  puts "=> Site configured with Pow, open `http://#{site_no_tld}.dev` to test site locally.\n"
48
49
  else
49
50
  puts "=> Site configured, run `siteleaf server` to test site locally.\n"
@@ -1,20 +1,18 @@
1
- require 'rest-client'
2
- require 'json'
1
+ require 'httparty'
3
2
 
4
3
  module Siteleaf
5
4
  class Client
6
5
  def self.auth(email, password)
7
- request = RestClient::Request.new(:url => Siteleaf.api_url('auth'), :method => :post, :user => email, :password => password)
8
6
  begin
9
- response = request.execute
10
- return JSON.parse(response) # parse JSON
7
+ request = HTTParty.post(Siteleaf.api_url('auth'), {:basic_auth => {:username => email, :password => password}})
8
+ return request.parsed_response # parse JSON
11
9
  rescue => e
12
10
  return e.inspect # error
13
11
  end
14
12
  end
15
13
 
16
14
  def self.get(path, params = nil)
17
- self.execute(:get, path, nil, params)
15
+ self.execute(:get, path, params)
18
16
  end
19
17
 
20
18
  def self.post(path, params)
@@ -25,23 +23,22 @@ module Siteleaf
25
23
  self.execute(:put, path, params)
26
24
  end
27
25
 
28
- def self.delete(path)
29
- self.execute(:delete, path)
26
+ def self.delete(path, params = nil)
27
+ self.execute(:delete, path, params)
30
28
  end
31
29
 
32
- def self.execute(method, path, payload = nil, params = nil)
30
+ def self.execute(method, path, params = nil)
33
31
  Siteleaf.load_settings if !Siteleaf.api_key
34
- request = RestClient::Request.new(:url => Siteleaf.api_url(path), :method => method, :payload => payload, :headers => { :params => params }, :user => Siteleaf.api_key, :password => Siteleaf.api_secret)
35
- #begin
36
- response = request.execute
37
- if response.headers[:content_type].to_s.include?('json')
38
- return JSON.parse(response) # parse JSON
32
+ begin
33
+ request = HTTParty.send(method, Siteleaf.api_url(path), {:body => params, :basic_auth => {:username => Siteleaf.api_key, :password => Siteleaf.api_secret}})
34
+ if request.respond_to?('parsed_response')
35
+ return request.parsed_response # parse JSON
39
36
  else
40
- return response # raw
37
+ return request # raw
41
38
  end
42
- #rescue => e
43
- # return e.inspect # error
44
- #end
39
+ rescue => e
40
+ return e.inspect # error
41
+ end
45
42
  end
46
43
  end
47
44
  end
@@ -44,7 +44,7 @@ module Siteleaf
44
44
  end
45
45
 
46
46
  def attributes=(attributes = {})
47
- attributes.each_pair { |k, v| k != "attributes" and self.instance_variable_set("@#{k}", v) }
47
+ attributes.each_pair { |k, v| self.instance_variable_set("@#{k}", v) }
48
48
  end
49
49
 
50
50
  def self.class_name
data/lib/siteleaf/page.rb CHANGED
@@ -4,6 +4,16 @@ module Siteleaf
4
4
  attr_accessor :title, :body, :slug, :url, :parent_id, :site_id, :published_at, :meta
5
5
  attr_reader :id, :created_at, :updated_at
6
6
 
7
+ def self.all
8
+ result = Client.get "#{self.endpoint}", {'include' => ['meta']}
9
+ result.map { |r| self.new(r) } if result
10
+ end
11
+
12
+ def self.find(id)
13
+ result = Client.get "#{self.endpoint}/#{id}", {'include' => ['meta']}
14
+ self.new(result) if result
15
+ end
16
+
7
17
  def create_endpoint
8
18
  "sites/#{self.site_id}/pages"
9
19
  end
@@ -13,12 +23,12 @@ module Siteleaf
13
23
  end
14
24
 
15
25
  def posts
16
- result = Client.get "pages/#{self.id}/posts"
26
+ result = Client.get "pages/#{self.id}/posts", {'include' => ['meta','taxonomy']}
17
27
  result.map { |r| Post.new(r) } if result
18
28
  end
19
29
 
20
30
  def pages
21
- result = Client.get "pages/#{self.id}/pages"
31
+ result = Client.get "pages/#{self.id}/pages", {'include' => ['meta']}
22
32
  result.map { |r| self.new(r) } if result
23
33
  end
24
34
 
data/lib/siteleaf/post.rb CHANGED
@@ -3,6 +3,16 @@ module Siteleaf
3
3
 
4
4
  attr_accessor :taxonomy
5
5
 
6
+ def self.all
7
+ result = Client.get "#{self.endpoint}", {'include' => ['meta','taxonomy']}
8
+ result.map { |r| self.new(r) } if result
9
+ end
10
+
11
+ def self.find(id)
12
+ result = Client.get "#{self.endpoint}/#{id}", {'include' => ['meta','taxonomy']}
13
+ self.new(result) if result
14
+ end
15
+
6
16
  def create_endpoint
7
17
  "pages/#{self.parent_id}/posts"
8
18
  end
@@ -42,7 +42,7 @@ module Siteleaf
42
42
  Rack::File.new(Dir.pwd).call(env)
43
43
  else
44
44
  template_data = nil
45
- is_asset = /(^assets|\.)/.match(path)
45
+ is_asset = /^(?!(sitemap|feed)\.xml)(assets|.*\.)/.match(path)
46
46
 
47
47
  if is_asset
48
48
  if asset = site.resolve(url) and asset_url = asset['file']['url']
@@ -1,3 +1,3 @@
1
1
  module Siteleaf
2
- VERSION = "0.8.3"
2
+ VERSION = "0.9.0"
3
3
  end
data/lib/siteleaf.rb CHANGED
@@ -8,25 +8,25 @@ require 'siteleaf/entity'
8
8
  require 'siteleaf/site'
9
9
  require 'siteleaf/page'
10
10
  require 'siteleaf/post'
11
- require 'siteleaf/meta'
12
11
  require 'siteleaf/user'
12
+ require 'rbconfig'
13
13
 
14
14
  module Siteleaf
15
15
 
16
16
  @api_base = 'https://api.siteleaf.com/v1'
17
-
17
+
18
18
  class << self
19
19
  attr_accessor :api_key, :api_secret, :api_base
20
20
  end
21
-
21
+
22
22
  def self.api_url(url='')
23
23
  "#{@api_base}/#{url}"
24
24
  end
25
-
25
+
26
26
  def self.settings_file
27
- "#{Etc.getpwuid.dir}/.siteleaf"
27
+ File.expand_path('~/.siteleaf')
28
28
  end
29
-
29
+
30
30
  def self.load_settings
31
31
  if File.exist?(self.settings_file)
32
32
  config = File.open(self.settings_file) do|file|
@@ -36,5 +36,5 @@ module Siteleaf
36
36
  self.api_secret = config[:api_secret] if config.has_key?(:api_secret)
37
37
  end
38
38
  end
39
-
39
+
40
40
  end
data/siteleaf.gemspec CHANGED
@@ -14,8 +14,8 @@ Gem::Specification.new do |gem|
14
14
 
15
15
  gem.required_ruby_version = '>= 1.8'
16
16
 
17
- gem.add_dependency 'rest-client'
18
- gem.add_dependency 'json'
17
+ gem.add_dependency 'json', '~> 1.7.7'
18
+ gem.add_dependency 'httparty'
19
19
  gem.add_dependency 'rack'
20
20
 
21
21
  gem.files = `git ls-files`.split($/)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: siteleaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,26 +9,26 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-05 00:00:00.000000000 Z
12
+ date: 2013-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rest-client
15
+ name: json
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 1.7.7
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 1.7.7
30
30
  - !ruby/object:Gem::Dependency
31
- name: json
31
+ name: httparty
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
@@ -76,7 +76,6 @@ files:
76
76
  - lib/siteleaf.rb
77
77
  - lib/siteleaf/client.rb
78
78
  - lib/siteleaf/entity.rb
79
- - lib/siteleaf/meta.rb
80
79
  - lib/siteleaf/page.rb
81
80
  - lib/siteleaf/post.rb
82
81
  - lib/siteleaf/server.rb
data/lib/siteleaf/meta.rb DELETED
@@ -1,24 +0,0 @@
1
- module Siteleaf
2
- class Meta < Entity
3
-
4
- attr_accessor :key, :value, :page_id, :post_id
5
- attr_reader :id
6
-
7
- def create_endpoint
8
- if self.page_id
9
- "pages/#{self.page_id}/meta"
10
- elsif self.post_id
11
- "posts/#{self.post_id}/meta"
12
- end
13
- end
14
-
15
- def post
16
- Post.find(self.post_id) if self.post_id
17
- end
18
-
19
- def page
20
- Page.find(self.page_id) if self.page_id
21
- end
22
-
23
- end
24
- end