alephant-preview 0.0.1

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: f4fd97409139665070cff877915e10c5d97e1ed7
4
+ data.tar.gz: acc3084e5e29a671813f3106b10d21098ab50586
5
+ SHA512:
6
+ metadata.gz: 5a84dcc2fd08f92934168e4bac6bfdb363c45f3e12dee8038cad5563460bb7cf19664662c4faf12463fa78ae74363a369df3c1f406a3ef979d44ef77b5845719
7
+ data.tar.gz: 9d455aab4499a6f16b127f5b947d49f59d89bb932a8ae3cde4491fef330dbf0056381d441b4fed0db1a78a9680f80aee54150845c0ea9c02e4f98295c013655a
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in alephant-preview.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Robert Kenny
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.
@@ -0,0 +1,29 @@
1
+ # Alephant::Preview
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'alephant-preview'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install alephant-preview
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/alephant-preview/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alephant/preview/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alephant-preview"
8
+ spec.version = Alephant::Preview::VERSION
9
+ spec.authors = ["Robert Kenny"]
10
+ spec.email = ["kenoir@gmail.com"]
11
+ spec.summary = "Preview component templates"
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "rspec"
21
+ spec.add_development_dependency "rspec-nc"
22
+ spec.add_development_dependency "guard"
23
+ spec.add_development_dependency "guard-rspec"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "pry-remote"
26
+ spec.add_development_dependency "pry-nav"
27
+ spec.add_development_dependency "bundler", "~> 1.5"
28
+ spec.add_development_dependency "rake"
29
+
30
+ spec.add_runtime_dependency 'sinatra'
31
+ spec.add_runtime_dependency 'faraday'
32
+ spec.add_runtime_dependency 'trollop'
33
+ spec.add_runtime_dependency 'rake'
34
+ spec.add_runtime_dependency 'mustache', '>= 0.99.5'
35
+
36
+ spec.add_runtime_dependency 'alephant'
37
+ end
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ require 'trollop'
5
+
6
+ root = Pathname.new(__FILE__).dirname.parent
7
+ lib_path = (root + 'lib').realdirpath
8
+
9
+ $LOAD_PATH.unshift(lib_path)
10
+
11
+ require 'alephant/preview'
12
+ require 'alephant/preview/tasks'
13
+
14
+ SUB_COMMANDS = %w(preview)
15
+ global_opts = Trollop::options do
16
+ banner <<-EOS
17
+ Static publishing to S3 based on SQS messages
18
+ Usage:
19
+ alephant-preview # Runs preview server
20
+ alephant-preview update # Attempts to update preview template
21
+ Dependent on the following environmen variables being set:
22
+ - STATIC_HOST_REGEX"static.(int|test|live).myhost.com"
23
+ - PREVIEW_TEMPLATE_URL"http://myapp.com/mustache_template"
24
+ EOS
25
+ stop_on SUB_COMMANDS
26
+ end
27
+
28
+ cmd = ARGV.shift # get the subcommand
29
+ case cmd
30
+ when nil
31
+ Rake::Task['alephant:preview:go'].invoke
32
+ when "update"
33
+ Rake::Task['alephant:preview:update'].invoke
34
+ else
35
+ Trollop::die "unknown subcommand #{cmd.inspect}"
36
+ end
37
+
@@ -0,0 +1,4 @@
1
+ require "alephant/preview/version"
2
+ require "alephant/preview/server"
3
+ require "alephant/preview/template"
4
+
@@ -0,0 +1,76 @@
1
+ require 'alephant/models/render_mapper'
2
+ require 'alephant/models/parser'
3
+
4
+ require 'alephant/preview/template/base'
5
+
6
+ require 'sinatra/base'
7
+ require 'faraday'
8
+ require 'json'
9
+ require 'uri'
10
+
11
+ module Alephant
12
+ module Preview
13
+ class Server < Sinatra::Base
14
+
15
+ get '/preview/:id/:template/:region/?:fixture?' do
16
+ render_preview
17
+ end
18
+
19
+ get '/component/:id/:template/?:fixture?' do
20
+ render_component
21
+ end
22
+
23
+ def render_preview
24
+ Template::Base.new(
25
+ { region => render_component },
26
+ preview_template_location
27
+ ).render
28
+ end
29
+
30
+ def render_component
31
+ ::Alephant::RenderMapper.new(id, base_path).create_renderer(template_file, fixture_data).render
32
+ end
33
+
34
+ private
35
+ def template
36
+ params['template']
37
+ end
38
+
39
+ def region
40
+ params['region']
41
+ end
42
+
43
+ def id
44
+ params['id']
45
+ end
46
+
47
+ def fixture
48
+ params['fixture'] || id
49
+ end
50
+
51
+ def fixture_data
52
+ parser.parse raw_fixture_data
53
+ end
54
+
55
+ def raw_fixture_data
56
+ File.open(fixture_location).read
57
+ end
58
+
59
+ def parser
60
+ @parser ||= Parser.new
61
+ end
62
+
63
+ def base_path
64
+ "#{Dir.pwd}/components"
65
+ end
66
+
67
+ def fixture_location
68
+ "#{base_path}/#{id}/fixtures/#{fixture}.json"
69
+ end
70
+
71
+ def preview_template_location
72
+ "#{Template.path}/templates/preview.mustache"
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,8 @@
1
+ require 'rake'
2
+ require 'pathname'
3
+
4
+ root = Pathname.new(__FILE__).dirname
5
+ task_path = (root + 'tasks').realdirpath
6
+
7
+ Dir["#{task_path}/**/*.rake"].each { |ext| load ext } if defined?(Rake)
8
+
@@ -0,0 +1,16 @@
1
+ require 'alephant/preview/server'
2
+ require 'alephant/preview/template'
3
+
4
+ namespace :alephant do
5
+ namespace :preview do
6
+ task :go do
7
+ Alephant::Preview::Server.run!
8
+ end
9
+ task :update do
10
+ Alephant::Preview::Template.update(
11
+ "#{::Alephant::Preview.path}/templates/preview.mustache"
12
+ )
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,16 @@
1
+ require 'alephant/preview/template/base'
2
+ require 'alephant/preview/template/updater'
3
+
4
+ module Alephant
5
+ module Preview
6
+ module Template
7
+ def self.path
8
+ "#{Dir.pwd}/components/lib"
9
+ end
10
+
11
+ def self.update(template_location)
12
+ Updater.new.update(template_location)
13
+ end
14
+ end
15
+ end
16
+ end
File without changes
@@ -0,0 +1,53 @@
1
+ require 'faraday'
2
+ require 'uri'
3
+
4
+ module Alephant
5
+ module Preview
6
+ module Template
7
+ class Updater
8
+ def template
9
+ response = Faraday.new(:url => host).get(path)
10
+ raise "Can't get template" if response.status != 200
11
+
12
+ apply_static_host_regex_to response.body
13
+ end
14
+
15
+ def update(template_location)
16
+ File.open(template_location, 'w') { |file|
17
+ file.write(template)
18
+ }
19
+ end
20
+
21
+ def host
22
+ "#{uri.scheme}://#{uri.host}"
23
+ end
24
+
25
+ def path
26
+ uri.path
27
+ end
28
+
29
+ def uri
30
+ return @uri if not @uri.nil?
31
+
32
+ uri_from_env = ENV['PREVIEW_TEMPLATE_URL']
33
+ raise Exception.new("PREVIEW_TEMPLATE_URL is unset!") if uri_from_env.nil?
34
+
35
+ @uri = URI(uri_from_env)
36
+ end
37
+
38
+ def apply_static_host_regex_to(string)
39
+ string.gsub(static_host_regex, '{{{static_host}}}')
40
+ end
41
+
42
+ def static_host_regex
43
+ return @static_host_regex if not @static_host_regex.nil?
44
+
45
+ static_host_regex_from_env = ENV['STATIC_HOST_REGEX']
46
+ raise Exception.new("STATIC_HOST_REGEX is unset!") if static_host_regex_from_env.nil?
47
+
48
+ @static_host_regex = Regexp.new(static_host_regex_from_env)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,5 @@
1
+ module Alephant
2
+ module Preview
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,270 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alephant-preview
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Robert Kenny
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-nc
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ prerelease: false
82
+ type: :development
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-remote
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ prerelease: false
96
+ type: :development
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-nav
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ prerelease: false
110
+ type: :development
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.5'
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ~>
121
+ - !ruby/object:Gem::Version
122
+ version: '1.5'
123
+ prerelease: false
124
+ type: :development
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirement: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ prerelease: false
138
+ type: :development
139
+ - !ruby/object:Gem::Dependency
140
+ name: sinatra
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirement: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ prerelease: false
152
+ type: :runtime
153
+ - !ruby/object:Gem::Dependency
154
+ name: faraday
155
+ version_requirements: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirement: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ prerelease: false
166
+ type: :runtime
167
+ - !ruby/object:Gem::Dependency
168
+ name: trollop
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirement: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - '>='
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ prerelease: false
180
+ type: :runtime
181
+ - !ruby/object:Gem::Dependency
182
+ name: rake
183
+ version_requirements: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirement: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - '>='
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ prerelease: false
194
+ type: :runtime
195
+ - !ruby/object:Gem::Dependency
196
+ name: mustache
197
+ version_requirements: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '>='
200
+ - !ruby/object:Gem::Version
201
+ version: 0.99.5
202
+ requirement: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - '>='
205
+ - !ruby/object:Gem::Version
206
+ version: 0.99.5
207
+ prerelease: false
208
+ type: :runtime
209
+ - !ruby/object:Gem::Dependency
210
+ name: alephant
211
+ version_requirements: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - '>='
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ requirement: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - '>='
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ prerelease: false
222
+ type: :runtime
223
+ description:
224
+ email:
225
+ - kenoir@gmail.com
226
+ executables:
227
+ - alephant-preview
228
+ extensions: []
229
+ extra_rdoc_files: []
230
+ files:
231
+ - .gitignore
232
+ - Gemfile
233
+ - LICENSE.txt
234
+ - README.md
235
+ - Rakefile
236
+ - alephant-preview.gemspec
237
+ - bin/alephant-preview
238
+ - lib/alephant/preview.rb
239
+ - lib/alephant/preview/server.rb
240
+ - lib/alephant/preview/tasks.rb
241
+ - lib/alephant/preview/tasks/preview.rake
242
+ - lib/alephant/preview/template.rb
243
+ - lib/alephant/preview/template/base.rb
244
+ - lib/alephant/preview/template/updater.rb
245
+ - lib/alephant/preview/version.rb
246
+ homepage: ''
247
+ licenses:
248
+ - MIT
249
+ metadata: {}
250
+ post_install_message:
251
+ rdoc_options: []
252
+ require_paths:
253
+ - lib
254
+ required_ruby_version: !ruby/object:Gem::Requirement
255
+ requirements:
256
+ - - '>='
257
+ - !ruby/object:Gem::Version
258
+ version: '0'
259
+ required_rubygems_version: !ruby/object:Gem::Requirement
260
+ requirements:
261
+ - - '>='
262
+ - !ruby/object:Gem::Version
263
+ version: '0'
264
+ requirements: []
265
+ rubyforge_project:
266
+ rubygems_version: 2.1.9
267
+ signing_key:
268
+ specification_version: 4
269
+ summary: Preview component templates
270
+ test_files: []