kajabi_theme 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a226ac57b32c655e054b10186d8cfa20ba0e5f9
4
+ data.tar.gz: 6d1a1f17771273adbd3e7fd9c0b45a2552d5b1d0
5
+ SHA512:
6
+ metadata.gz: ff9d7ffdc13424417c9aec0ceecb1e85d0c4098f8acd4e3a91100d8e5dc700739e4bcbfd802603758a2323294a376940c73742b5b28ce35aec78998813280a7f
7
+ data.tar.gz: c8fdc43d3d866996d81fafd98e2e74d86e4b09258303d05f76bbbd54b81c44bc92f49af22b6d88d5cf709a83e1080c37a4b712b3885f1edfe03014de677a073c
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kajabi_theme.gemspec
4
+ gemspec
@@ -0,0 +1,36 @@
1
+ # KajabiTheme
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kajabi_theme`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kajabi_theme'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kajabi_theme
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kajabi_theme.
36
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kajabi_theme"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby -U
2
+
3
+ # This allows kajabi_theme to run easily from a git checkout without install.
4
+ # Hat tip to chriseppstein of Compass fame for the code for this
5
+ def fallback_load_path(path)
6
+ retried = false
7
+ begin
8
+ yield
9
+ rescue LoadError
10
+ unless retried
11
+ $: << path
12
+ retried = true
13
+ retry
14
+ end
15
+ raise
16
+ end
17
+ end
18
+
19
+ fallback_load_path(File.join(File.dirname(__FILE__), '..', 'lib')) do
20
+ require 'kajabi_theme'
21
+ end
22
+
23
+ KajabiTheme::CLI.start(ARGV)
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kajabi_theme/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kajabi_theme"
8
+ spec.version = KajabiTheme::VERSION
9
+ spec.authors = ["Jeremy Saenz"]
10
+ spec.email = ["jeremy.saenz@gmail.com"]
11
+
12
+ spec.summary = %q{Command line tool for developing themes}
13
+ spec.description = %q{Command line tool to help with developing Kajabi themes. Provides some commands detect changes of local theme files and sync them with a theme on Kajabi}
14
+ spec.homepage = "http://www.kajabi.co"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "thor"
22
+ spec.add_dependency "typhoeus"
23
+ spec.add_dependency "filewatcher"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec"
28
+ end
@@ -0,0 +1,3 @@
1
+ require "kajabi_theme/version"
2
+ require "kajabi_theme/cli"
3
+ require "kajabi_theme/util"
@@ -0,0 +1,175 @@
1
+ require "thor"
2
+ require "typhoeus"
3
+ require "filewatcher"
4
+
5
+ require "base64"
6
+ require "json"
7
+ require "time"
8
+ require "yaml"
9
+
10
+ module KajabiTheme
11
+ class CLI < Thor
12
+ include Thor::Actions
13
+
14
+ FOLDERS=%w[config templates layouts snippets assets].freeze
15
+ ACCOUNT_SETTINGS_URL="https://app.newkajabi.com/admin/settings/account"
16
+
17
+ attr_reader :name
18
+ attr_reader :updated_at
19
+ attr_reader :created_at
20
+ attr_reader :presigned_post
21
+
22
+ desc "sync", "Sync all files to Kajabi"
23
+ def sync(force=true)
24
+ refresh!
25
+ (force ? files : changed_files).each {|f| send_file(f)}
26
+ hydra.run
27
+ end
28
+
29
+ desc "watch", "Sync and watch for changes"
30
+ def watch
31
+ refresh!
32
+ sync(false)
33
+
34
+ say "Watching for file changes..."
35
+
36
+ FileWatcher.new(FOLDERS).watch do |filename|
37
+ say "Change detected: #{filename}"
38
+ send_file(filename)
39
+ hydra.run
40
+ end
41
+ end
42
+
43
+ desc "configure", "Configure the current directory for syncing"
44
+ def configure
45
+ theme_id = ask("Kajabi Theme ID:")
46
+ api_key = ask("API Key (#{ACCOUNT_SETTINGS_URL}):")
47
+ api_secret = ask("API Secret (#{ACCOUNT_SETTINGS_URL}):")
48
+
49
+ create_file "config.yml" do
50
+ { theme_id: theme_id, api_key: api_key, api_secret: api_secret }.to_yaml
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def config
57
+ @config ||= YAML.load_file "config.yml"
58
+ rescue
59
+ say "Unable to load config.yml. Have you run `kajabi-theme configure` in your theme directory?", :red
60
+ exit 1
61
+ end
62
+
63
+ def assets_url
64
+ File.join(host, "api/edge/themes/#{id}/assets.json")
65
+ end
66
+
67
+ def host
68
+ @host ||= config[:host] || "https://app.newkajabi.com/"
69
+ end
70
+
71
+ def id
72
+ config[:theme_id]
73
+ end
74
+
75
+ def api_key
76
+ config[:api_key]
77
+ end
78
+
79
+ def api_secret
80
+ config[:api_secret]
81
+ end
82
+
83
+ def hydra
84
+ @hydra ||= Typhoeus::Hydra.hydra
85
+ end
86
+
87
+ def http_credentials
88
+ "#{api_key}:#{api_secret}"
89
+ end
90
+
91
+ def refresh!
92
+ request = Typhoeus::Request.new(assets_url, userpwd: http_credentials)
93
+ handle_request request do |response|
94
+ json = JSON[response.body]
95
+ @name = json["name"]
96
+ @updated_at = json["updated_at"]
97
+ @created_at = json["created_at"]
98
+ @presigned_post = json["presigned_post"]
99
+ end
100
+ response = request.run
101
+ unless response.success?
102
+ exit 1
103
+ end
104
+ end
105
+
106
+ def files
107
+ FOLDERS.map do |f|
108
+ Dir["#{f}/*.*"]
109
+ end.reduce(:+)
110
+ end
111
+
112
+ def handle_request(request, &success_block)
113
+ request.on_complete do |response|
114
+ if response.success?
115
+ success_block.call(response)
116
+ elsif response.timed_out?
117
+ say "Request timed out", :red
118
+ elsif response.code == 0
119
+ # Could not get an http response, something's wrong.
120
+ say "Request timed out", :red
121
+ else
122
+ # Received a non-successful http response.
123
+ say "HTTP request failed: #{response.code.to_s} #{response.body.to_s}", :red
124
+ end
125
+ end
126
+ end
127
+
128
+ def changes_detected?
129
+ changed_files.present?
130
+ end
131
+
132
+ def changed_files
133
+ files.select { |file| Time.parse(updated_at) < File.mtime(file).utc }
134
+ end
135
+
136
+ def send_file(file)
137
+ if Util.editable?(file)
138
+ send_editable_file(file)
139
+ else
140
+ send_asset_file(file)
141
+ end
142
+ end
143
+
144
+ def send_editable_file(file)
145
+ request = Typhoeus::Request.new(
146
+ assets_url,
147
+ userpwd: http_credentials,
148
+ method: :put,
149
+ headers: { "content-type" => "application/x-www-form-urlencoded" },
150
+ body: { asset: { key: file, content: File.read(file) }}
151
+ )
152
+ handle_request request do |response|
153
+ say "Uploaded: #{file}", :green
154
+ end
155
+ hydra.queue(request)
156
+ request
157
+ end
158
+
159
+ def send_asset_file(file)
160
+ body = presigned_post["fields"]
161
+ request = Typhoeus::Request.new(
162
+ presigned_post["url"],
163
+ method: :post,
164
+ body: body.merge("file" => File.open(file, "r"))
165
+ )
166
+
167
+ handle_request request do |response|
168
+ say "Uploaded: #{file}", :green
169
+ end
170
+
171
+ hydra.queue(request)
172
+ request
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,19 @@
1
+ module KajabiTheme
2
+ class Util
3
+ def self.editable?(name)
4
+ content_type(name).start_with?("text/") ||
5
+ content_type(name) == "application/javascript" ||
6
+ content_type(name) == "application/json"
7
+ end
8
+
9
+ def self.content_type(name)
10
+ if name.end_with?(".woff2")
11
+ "application/font-woff2"
12
+ elsif name.end_with?(".scss") || name.end_with?(".scss.liquid")
13
+ "text/css"
14
+ else
15
+ MIME::Types.type_for(name.sub('.liquid', '')).first.content_type rescue "text/plain"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module KajabiTheme
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kajabi_theme
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Saenz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: typhoeus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: filewatcher
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
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Command line tool to help with developing Kajabi themes. Provides some
98
+ commands detect changes of local theme files and sync them with a theme on Kajabi
99
+ email:
100
+ - jeremy.saenz@gmail.com
101
+ executables:
102
+ - kajabi-theme
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - exe/kajabi-theme
115
+ - kajabi_theme.gemspec
116
+ - lib/kajabi_theme.rb
117
+ - lib/kajabi_theme/cli.rb
118
+ - lib/kajabi_theme/util.rb
119
+ - lib/kajabi_theme/version.rb
120
+ homepage: http://www.kajabi.co
121
+ licenses: []
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.5
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Command line tool for developing themes
143
+ test_files: []
144
+ has_rdoc: