middle_drive 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ba7b7747573e5f6690179713223393910fa2664b
4
+ data.tar.gz: acb0ca669048f636ac2c773438ac1a5f9b75ce7d
5
+ SHA512:
6
+ metadata.gz: 4006127ef94388103cd1c0b8bf756a4d7f8e6fcb90a1c390753e527f8eb70dd8bea5868d69349d237c46a534981a160c8fb3d514d7ca0cf787a50935c9945f72
7
+ data.tar.gz: 67739a85be32aa0a59724aee84592316c4f5445c266d66c602a9f6f2f8e18ca3cd665cbce2029e643817ab5c48f3d483dd12154a5aa5e309a1c0c6f1a38317a5
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ .idea
20
+ middle_drive.yml
21
+ build/source/images/*
22
+ build/locales/*
23
+ build/pages.yml
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in middle_drive.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ziga Vidic
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # MiddleDrive
2
+
3
+ ## Quick start
4
+
5
+ gem install middleman
6
+ middleman init new_site
7
+
8
+ To `Gemfile` in `new_site` add `middle_drive`
9
+
10
+ gem 'middle_drive'
11
+
12
+ Then run
13
+
14
+ cd new_site
15
+ bundle
16
+ middle_drive init
17
+
18
+ ## Manual install
19
+
20
+ gem install middle_drive
21
+
22
+ ## Setup
23
+
24
+ middle_drive init
25
+
26
+ ## Usage
27
+
28
+ middle_drive
29
+
30
+ ## Conventions
31
+
32
+ `pages` must be a spreadsheet which contains pages, separated into worksheets (tabs).
33
+
34
+ ### Middleman config for dynamic pages
35
+
36
+ Copy `config.MIDDLEMAN.rb` to `config.rb` to your Middleman app.
37
+
38
+ ## TODO
39
+ - http://middlemanapp.com/advanced/local-data/
40
+ - http://tvaughan.github.io/middleman-deploy/
41
+ - [Partials](http://middlemanapp.com/templates/) for debug info
42
+
43
+ - when building from scratch it would be better to start building `pages.yml`, `data.yml`, `en.yml` files locally and
44
+ then run init to build structure on google drive
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/middle_drive ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if ARGV.length == 0
4
+ require 'middle_drive'
5
+ MiddleDrive.run
6
+ elsif ARGV[0] == 'init'
7
+ current_user_dir = Dir.pwd
8
+ gem_dir = "#{File.dirname(__FILE__)}/.."
9
+
10
+ cmd_middle_drive_settings = "cp #{gem_dir}/middle_drive.SAMPLE.yml #{current_user_dir}/middle_drive.yml"
11
+ cmd_middleman_config = "cp #{gem_dir}/config.MIDDLEMAN.rb #{current_user_dir}/config.rb"
12
+
13
+ p 'Writing middle_drive.yml'
14
+ system(cmd_middle_drive_settings)
15
+
16
+ p 'Writing config.rb for'
17
+ system(cmd_middleman_config)
18
+ end
File without changes
File without changes
@@ -0,0 +1,88 @@
1
+ require 'yaml'
2
+
3
+ PAGES = YAML.load(File.open('pages.yml'))
4
+ MIDDLE_DRIVE_CONFIG = YAML.load(File.open('middle_drive.yml'))
5
+
6
+ LANGS = MIDDLE_DRIVE_CONFIG['site']['languages']
7
+ DEFAULT_LANGUAGE = MIDDLE_DRIVE_CONFIG['site']['default_language']
8
+
9
+ ###
10
+ # Dynamic pages
11
+ ###
12
+ PAGES['pages'].each do |page|
13
+ page_name = page[0]
14
+ template_name = page[1]
15
+
16
+ # for each page create default language without locale in url
17
+ proxy page_name,
18
+ "#{template_name}-template.html",
19
+ :locals => { :page_name => page_name, :locale => DEFAULT_LANGUAGE },
20
+ :ignore => true
21
+
22
+ LANGS.each do |locale|
23
+ proxy "#{locale}/#{page_name}",
24
+ "#{template_name}-template.html",
25
+ :locals => { :page_name => page_name, :locale => locale },
26
+ :ignore => true
27
+ end
28
+ end
29
+
30
+ ###
31
+ # Helpers
32
+ ###
33
+ # Methods defined in the helpers block are available in templates
34
+ helpers do
35
+ def trans(page_name, key, locale)
36
+ I18n.t("#{page_name}.#{key}", locale: locale)
37
+ end
38
+ end
39
+
40
+ ###
41
+ # Compass
42
+ ###
43
+
44
+ # Change Compass configuration
45
+ # compass_config do |config|
46
+ # config.output_style = :compact
47
+ # end
48
+
49
+ ###
50
+ # Page options, layouts, aliases and proxies
51
+ ###
52
+
53
+ # Per-page layout changes:
54
+ #
55
+ # With no layout
56
+ # page "/path/to/file.html", :layout => false
57
+ #
58
+ # With alternative layout
59
+ # page "/path/to/file.html", :layout => :otherlayout
60
+ #
61
+ # A path which all have the same layout
62
+ # with_layout :admin do
63
+ # page "/admin/*"
64
+ # end
65
+
66
+ # Automatic image dimensions on image_tag helper
67
+ # activate :automatic_image_sizes
68
+
69
+ # Reload the browser automatically whenever files change
70
+ activate :livereload
71
+
72
+ # http://middlemanapp.com/advanced/localization/
73
+ # set path so all templates can use t helper, otherwise only templates in localizable directory would work
74
+ activate :i18n, :path => ''
75
+
76
+ set :css_dir, 'stylesheets'
77
+ set :js_dir, 'javascripts'
78
+ set :images_dir, 'images'
79
+
80
+ # Build-specific configuration
81
+ configure :build do
82
+ activate :minify_css
83
+ activate :minify_javascript
84
+ # Use relative URLs
85
+ # activate :relative_assets
86
+ # Or use a different image path
87
+ # set :http_path, "/Content/images/"
88
+ end
@@ -0,0 +1,23 @@
1
+ require 'yaml'
2
+
3
+ module MiddleDrive
4
+ module Config
5
+
6
+ @settings = YAML.load(File.open('middle_drive.yml'))
7
+
8
+ # 'gdrive.username' => @settings['gdrive']['username']
9
+ def self.get(key)
10
+ keys = key.split('.')
11
+ values = @settings
12
+ keys.each do |k|
13
+ values = values[k]
14
+ end
15
+ values
16
+ end
17
+
18
+ def self.max_languages
19
+ 5
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ module MiddleDrive
2
+ class Image
3
+
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)
8
+ end
9
+
10
+ def download(build_path)
11
+ @images.files.each do |image_file|
12
+ save_to = "#{build_path}/#{@images_path}/#{image_file.title}"
13
+
14
+ if File.exist?(save_to)
15
+ puts "File #{save_to} already exists..."
16
+ else
17
+ puts "Downloading #{image_file.title} to #{save_to}..."
18
+ image_file.download_to_file(save_to)
19
+ end
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,60 @@
1
+ module MiddleDrive
2
+ class Page
3
+
4
+ def initialize(site)
5
+ pages_document_title = MiddleDrive::Config.get('site.pages')
6
+ @languages = MiddleDrive::Config.get('site.languages')
7
+ @pages_document = site.spreadsheets.select { |s| s.title == pages_document_title }.first
8
+ end
9
+
10
+ def build(path)
11
+ # each tab is a page
12
+ pages = {'pages' => {}}
13
+
14
+ # init lang hash
15
+ lang_keys = {}
16
+ @languages.each do |lang|
17
+ lang_keys[lang] = {}
18
+ end
19
+
20
+ @pages_document.worksheets.each do |page|
21
+ puts "Building key value pairs for page named #{page.title}"
22
+ # in very first row we specify page's template
23
+ pages['pages'][page.title] = page[1, 1]
24
+
25
+ @languages.each do |lang|
26
+ lang_keys = load_language_values(lang_keys, page, lang)
27
+ end
28
+ end
29
+
30
+ @languages.each do |lang|
31
+ output = {}
32
+ output[lang] = lang_keys[lang]
33
+ File.write("#{path}/locales/#{lang}.yml", output.to_yaml)
34
+ end
35
+
36
+ File.write(path + '/pages.yml', pages.to_yaml)
37
+ end
38
+
39
+ def load_language_values(hash, sheet, lang)
40
+ column_index = get_language_column_index(sheet, lang)
41
+ hash[lang][sheet.title] = {}
42
+
43
+ (2..sheet.num_rows).each do |row|
44
+ key = sheet[row, 1]
45
+ value = sheet[row, column_index]
46
+ hash[lang][sheet.title][key] = value
47
+ end
48
+
49
+ hash
50
+ end
51
+
52
+ def get_language_column_index(sheet, lang)
53
+ (1..MiddleDrive::Config.max_languages).each do |column|
54
+ return column if sheet[1, column] == lang
55
+ end
56
+ 0
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module MiddleDrive
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,30 @@
1
+ require 'google_drive'
2
+ require 'google_drive/collection'
3
+
4
+ require 'middle_drive/version'
5
+ require 'middle_drive/config'
6
+ require 'middle_drive/image'
7
+ require 'middle_drive/page'
8
+
9
+ module MiddleDrive
10
+
11
+ def self.run
12
+ # Logs in.
13
+ # You can also use OAuth. See document of
14
+ # GoogleDrive.login_with_oauth for details.
15
+ username = MiddleDrive::Config.get('gdrive.username')
16
+ password = MiddleDrive::Config.get('gdrive.password')
17
+ site_collection_title = MiddleDrive::Config.get('site.collection')
18
+ session = GoogleDrive.login(username, password)
19
+ # site is our main folder/collection so we only search within it
20
+ site = session.collection_by_title(site_collection_title)
21
+ build_path = MiddleDrive::Config.get('middleman.build_path')
22
+
23
+ i = Image.new(site)
24
+ i.download(build_path)
25
+
26
+ p = Page.new(site)
27
+ p.build(build_path)
28
+ end
29
+
30
+ end
@@ -0,0 +1,16 @@
1
+ gdrive:
2
+ username: user@example.com
3
+ password: password
4
+
5
+ site:
6
+ collection: middleman
7
+ images_collection: images
8
+ pages: pages
9
+ languages: # order matters here!
10
+ - en
11
+ - sl
12
+ default_language: en
13
+
14
+ middleman:
15
+ build_path: .
16
+ images_path: source/images
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'middle_drive/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'middle_drive'
8
+ spec.version = MiddleDrive::VERSION
9
+ spec.authors = ['Ziga Vidic']
10
+ spec.email = ['zigomir@gmail.com']
11
+ spec.description = %q{Integrate Middleman and Google Drive}
12
+ spec.summary = %q{Will sync Google Drive spreadsheets and images with Middleman to use it as CMS.}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = %w(lib)
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+
24
+ spec.add_runtime_dependency 'google_drive'
25
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middle_drive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ziga Vidic
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: google_drive
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Integrate Middleman and Google Drive
56
+ email:
57
+ - zigomir@gmail.com
58
+ executables:
59
+ - middle_drive
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .ruby-version
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/middle_drive
70
+ - build/locales/.gitkeep
71
+ - build/source/images/.gitkeep
72
+ - config.MIDDLEMAN.rb
73
+ - lib/middle_drive.rb
74
+ - lib/middle_drive/config.rb
75
+ - lib/middle_drive/image.rb
76
+ - lib/middle_drive/page.rb
77
+ - lib/middle_drive/version.rb
78
+ - middle_drive.SAMPLE.yml
79
+ - middle_drive.gemspec
80
+ homepage: ''
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.0.2
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Will sync Google Drive spreadsheets and images with Middleman to use it as
104
+ CMS.
105
+ test_files: []