middle_drive 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae7dbdefe594f689969acb1a2b40ad63e6e0d950
4
- data.tar.gz: e98c9f4473c43bfff27a9e5767b1255048eac2b9
3
+ metadata.gz: 4aedc6854af898105aaaa9dadfb57705174043b6
4
+ data.tar.gz: 50879e64e6400fe860954653ce9cb6d83c0ec808
5
5
  SHA512:
6
- metadata.gz: 7c90da3f1721d1e4dd50fe805c02bccd5698e7ba39fec2b15c6953e4560201ad4be3c47a0a10c08857d06522073bf5cbfdb75daa165e5f8f8e7e776140f245d3
7
- data.tar.gz: bd5362f1dfc25035650dfcc10b7a7ac86ec7d79c3646e8dec574d12c24bb7414c4d08966e5557ecc983c4d5c026adb178b6f9a3634e9d96d7f3c6bc2a689a158
6
+ metadata.gz: 6f5e7f7e6973d4c7d9b1e4ee7c77ddec77e1db30cd33f3dd59e42919947ccf97fc0ffc7d70fa959239c7fb34ef205e31431a4a38b310dc62baa9f6f1bc91bd29
7
+ data.tar.gz: 3be7a42b0e39472b77845406ddbba5681ec3372533fb84346009d498922bc44366cfdacf5b6314271a9aa3bdc23901b1400fa66fb4a56468ce0de6f9ce1b19d1
data/.gitignore CHANGED
@@ -20,4 +20,5 @@ tmp
20
20
  middle_drive.yml
21
21
  build/source/images/*
22
22
  build/locales/*
23
+ build/data/*
23
24
  build/pages.yml
data/README.md CHANGED
@@ -28,10 +28,28 @@ Then run
28
28
  ### Google drive setup conventions
29
29
 
30
30
  - create a new collection in your google drive. Name it the same like in `middle_drive.yml`'s `site.collection` value.
31
- - create google spreadsheet named `pages` inside this collection. You can name it differently if you specify it for `site.pages`
31
+ - create google spreadsheet named `pages` inside this `site.collection`
32
32
  - each tab in this spreadsheet represents a page
33
33
  - value in first row and first column represents a template which will be used by middleman
34
34
  ![Example](/img/spreadsheet.png)
35
+ - create google spreadsheet named `data` inside `site.collection`
36
+ - each tab in this spreadsheet represents different list
37
+ - first data cell represents data type, which can be any of `array`, `hash` and `list`
38
+ - to display image just use this Middleman helper
39
+
40
+ ```erb
41
+ <%= image_tag data.article.article.image %>
42
+ ```
43
+
44
+ - to display list type use this
45
+
46
+ ```erb
47
+ <% data.blog.blog.each do |blog_post| %>
48
+ <h2><%= blog_post.title %></h2>
49
+ <%= blog_post.content %>
50
+ <span><%= blog_post.date %></span>
51
+ <% end %>
52
+ ```
35
53
 
36
54
  ## Usage
37
55
 
@@ -41,9 +59,8 @@ This command will sync images and page information from your Google Drive collec
41
59
  `middle_drive.yml` file.
42
60
 
43
61
  ## TODO
44
- - http://middlemanapp.com/advanced/local-data/
45
62
  - http://tvaughan.github.io/middleman-deploy/
63
+ - separate project for triggering sync between a site and drive
46
64
  - [Partials](http://middlemanapp.com/templates/) for debug info
47
-
48
65
  - when building from scratch it would be better to start building `pages.yml`, `data.yml`, `en.yml` files locally and
49
66
  then run init to build structure on google drive
data/lib/middle_drive.rb CHANGED
@@ -3,18 +3,18 @@ require 'google_drive/collection'
3
3
 
4
4
  require 'middle_drive/version'
5
5
  require 'middle_drive/config'
6
+
6
7
  require 'middle_drive/image'
7
8
  require 'middle_drive/page'
9
+ require 'middle_drive/data'
8
10
 
9
11
  module MiddleDrive
10
12
 
11
13
  def self.run
12
- # Logs in.
13
- # You can also use OAuth. See document of
14
- # GoogleDrive.login_with_oauth for details.
15
14
  username = MiddleDrive::Config.get('gdrive.username')
16
15
  password = MiddleDrive::Config.get('gdrive.password')
17
16
  site_collection_title = MiddleDrive::Config.get('site.collection')
17
+
18
18
  session = GoogleDrive.login(username, password)
19
19
  # site is our main folder/collection so we only search within it
20
20
  site = session.collection_by_title(site_collection_title)
@@ -25,6 +25,9 @@ module MiddleDrive
25
25
 
26
26
  p = Page.new(site)
27
27
  p.build(build_path)
28
+
29
+ d = Data.new(site)
30
+ d.build(build_path)
28
31
  end
29
32
 
30
33
  end
@@ -0,0 +1,48 @@
1
+ module MiddleDrive
2
+ class Data
3
+
4
+ def initialize(site)
5
+ @data_document = site.spreadsheets.select { |s| s.title == 'data' }.first
6
+ end
7
+
8
+ def build(path)
9
+ data_path = "#{path}/data"
10
+ Dir.mkdir(data_path) unless File.exists?(data_path)
11
+
12
+ @data_document.worksheets.each do |sheet|
13
+ save_to = "#{data_path}/#{sheet.title}.yml"
14
+ data = {}
15
+ puts "Building list named #{sheet.title}"
16
+
17
+ data_type = sheet[1, 1]
18
+
19
+ if data_type == 'array' or data_type == 'hash'
20
+ data[sheet.title] = [] if data_type == 'array'
21
+ data[sheet.title] = {} if data_type == 'hash'
22
+
23
+ (2..sheet.num_rows).each do |row|
24
+ data[sheet.title] << sheet[row, 1] if data_type == 'array' # only one column
25
+ data[sheet.title][sheet[row, 1]] = sheet[row, 2] if data_type == 'hash'
26
+ end
27
+ elsif data_type == 'list'
28
+ data = build_list(sheet)
29
+ end
30
+
31
+ File.write(save_to, data.to_yaml)
32
+ end
33
+ end
34
+
35
+ def build_list(sheet)
36
+ data = { sheet.title => [] }
37
+ (2..sheet.num_rows).each do |row|
38
+ list_object = {}
39
+ (2..sheet.num_cols).each do |col|
40
+ list_object[sheet[1, col]] = sheet[row, col]
41
+ end
42
+ data[sheet.title] << list_object
43
+ end
44
+ data
45
+ end
46
+
47
+ end
48
+ end
@@ -2,14 +2,14 @@ module MiddleDrive
2
2
  class Image
3
3
 
4
4
  def initialize(site)
5
- site_images_collection_title = MiddleDrive::Config.get('site.images_collection')
6
- @images_path = MiddleDrive::Config.get('middleman.images_path')
7
- @images = site.subcollection_by_title(site_images_collection_title)
5
+ @images = site.subcollection_by_title('images')
8
6
  end
9
7
 
10
- def download(build_path)
8
+ def download(path)
9
+ Dir.mkdir(path) unless File.exists?(path)
10
+
11
11
  @images.files.each do |image_file|
12
- save_to = "#{build_path}/#{@images_path}/#{image_file.title}"
12
+ save_to = "#{path}/source/images/#{image_file.title}"
13
13
 
14
14
  if File.exist?(save_to)
15
15
  puts "File #{save_to} already exists..."
@@ -2,12 +2,14 @@ module MiddleDrive
2
2
  class Page
3
3
 
4
4
  def initialize(site)
5
- pages_document_title = MiddleDrive::Config.get('site.pages')
6
5
  @languages = MiddleDrive::Config.get('site.languages')
7
- @pages_document = site.spreadsheets.select { |s| s.title == pages_document_title }.first
6
+ @pages_document = site.spreadsheets.select { |s| s.title == 'pages' }.first
8
7
  end
9
8
 
10
9
  def build(path)
10
+ locales_path = "#{path}/locales"
11
+ Dir.mkdir(locales_path) unless File.exists?(locales_path)
12
+
11
13
  # each tab is a page
12
14
  pages = {'pages' => {}}
13
15
 
@@ -30,10 +32,10 @@ module MiddleDrive
30
32
  @languages.each do |lang|
31
33
  output = {}
32
34
  output[lang] = lang_keys[lang]
33
- File.write("#{path}/locales/#{lang}.yml", output.to_yaml)
35
+ File.write("#{locales_path}/#{lang}.yml", output.to_yaml)
34
36
  end
35
37
 
36
- File.write(path + '/pages.yml', pages.to_yaml)
38
+ File.write("#{path}/pages.yml", pages.to_yaml)
37
39
  end
38
40
 
39
41
  def load_language_values(hash, sheet, lang)
@@ -1,3 +1,3 @@
1
1
  module MiddleDrive
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -4,8 +4,6 @@ gdrive:
4
4
 
5
5
  site:
6
6
  collection: middleman
7
- images_collection: images
8
- pages: pages
9
7
  languages: # order matters here!
10
8
  - en
11
9
  - sl
@@ -13,4 +11,3 @@ site:
13
11
 
14
12
  middleman:
15
13
  build_path: .
16
- images_path: source/images
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middle_drive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ziga Vidic
@@ -67,12 +67,14 @@ files:
67
67
  - README.md
68
68
  - Rakefile
69
69
  - bin/middle_drive
70
+ - build/data/.gitkeep
70
71
  - build/locales/.gitkeep
71
72
  - build/source/images/.gitkeep
72
73
  - config.MIDDLEMAN.rb
73
74
  - img/spreadsheet.png
74
75
  - lib/middle_drive.rb
75
76
  - lib/middle_drive/config.rb
77
+ - lib/middle_drive/data.rb
76
78
  - lib/middle_drive/image.rb
77
79
  - lib/middle_drive/page.rb
78
80
  - lib/middle_drive/version.rb