alephant-preview 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6145f10012de3dabfe234787f636e5a8b011ad5e
4
- data.tar.gz: ecdf7211609f469e812feb7cc856b0228a8af42c
3
+ metadata.gz: 6ca692cb8be7c816e8dfe71d2bc2ce9adfb73352
4
+ data.tar.gz: 05aeb2aacfc0e0ac62924dd27e44d3496866a8ed
5
5
  SHA512:
6
- metadata.gz: 9ebf87172b14488e9fe2081077234dc78d72d11c4170ad48a174ae220ee8af3f8a4d1dd40737d75c0af0a37b2d2f79f937d5d01d79c7e87d9b61d87db00a6f6b
7
- data.tar.gz: 54719f3ceb52daa9db26cbfd9ea4358ad89434bb7a13a0f26923449db3692ede5435e56a41cd3b150e2bb7bdb036ac43bc201a5d638b1f8a6a4aa944f14b5029
6
+ metadata.gz: 16b8979f67cea3ddb445fdccfd4875528bcd01e0c8cadc8a20acb32210074a2dc62bafff338b46fecd65572341fd5e4c0bc7165979d509fa4076bd4fdc6dc0c8
7
+ data.tar.gz: 892dc0f2591fc2c16dbfe3278bb200e23b8a713aa81f6c3a9439fe144c29a58b947e67a667f9c4b34ee18e9a6779a0047f2f461eaa20dedb88aaa411b56d02b5
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Alephant::Preview
2
2
 
3
- TODO: Write a gem description
3
+ Provides an in-page preview of components during development
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,61 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Provide a view in a folder:
22
+
23
+ ```
24
+ └── components
25
+ └── group_name
26
+ ├── models
27
+ │   └── foo.rb
28
+ ├── fixtures
29
+ │   └── foo.json
30
+ └── templates
31
+ └── foo.mustache
32
+ ```
33
+
34
+ `alephant-preview`
35
+
36
+ The included preview server allows you to see the html generated by your
37
+ templates, both standalone and in the context of a page.
38
+
39
+ ###Standalone
40
+
41
+ `/component/:id/?:fixture?`
42
+
43
+ ###Full page preview
44
+
45
+ `/preview/:group_name/:id/:region/?:fixture?`
46
+
47
+ `group_name` is the sub_folder that contains your templates
48
+
49
+ `id` is the component/folder name
50
+
51
+ `template` is the mustache template file name
52
+
53
+ `location_in_page` should be something like (for example) `page_head` (specified
54
+ within a `preview.mustache` file that the consuming application needs to
55
+ create).
56
+
57
+ - `http://localhost:4567/preview/group_name/id/template/location_in_page`
58
+
59
+
60
+ ####Updating preview
61
+
62
+ `alephant-preview update`
63
+
64
+ When viewing the component in the context of a page, you'll need to retrieve a
65
+ mustache template to provide the page context.
66
+
67
+ When performing an update a regex is applied to replace the static hostnames in
68
+ the retrieved html.
69
+
70
+ **Environment Variables**
71
+
72
+ ```sh
73
+ STATIC_HOST_REGEX="static.(sandbox.dev|int|test|stage|live).yourapp(i)?.com\/"
74
+ PREVIEW_TEMPLATE_URL="http://yourapp.com/template"
75
+ ```
22
76
 
23
77
  ## Contributing
24
78
 
@@ -33,5 +33,5 @@ Gem::Specification.new do |spec|
33
33
  spec.add_runtime_dependency 'rake'
34
34
  spec.add_runtime_dependency 'mustache', '>= 0.99.5'
35
35
 
36
- spec.add_runtime_dependency 'alephant'
36
+ spec.add_runtime_dependency 'alephant-renderer'
37
37
  end
@@ -1,4 +1,6 @@
1
- require 'alephant/models/render_mapper'
1
+ require 'alephant/renderer'
2
+ require 'alephant/views'
3
+
2
4
  require 'alephant/models/parser'
3
5
 
4
6
  require 'alephant/preview/template/base'
@@ -11,6 +13,7 @@ require 'uri'
11
13
  module Alephant
12
14
  module Preview
13
15
  class Server < Sinatra::Base
16
+ DEFAULT_LOCATION = 'components'
14
17
 
15
18
  get '/preview/:id/:template/:region/?:fixture?' do
16
19
  render_preview
@@ -28,10 +31,23 @@ module Alephant
28
31
  end
29
32
 
30
33
  def render_component
31
- ::Alephant::RenderMapper.new(id, base_path).create_renderer(template_file, fixture_data).render
34
+ ::Alephant::Renderer.create(template, base_path, model).render
32
35
  end
33
36
 
34
37
  private
38
+ def model
39
+ require model_location
40
+ ::Alephant::Views.get_registered_class(id).new(fixture_data)
41
+ end
42
+
43
+ def base_path
44
+ File.join(Dir.pwd, DEFAULT_LOCATION, id)
45
+ end
46
+
47
+ def model_location
48
+ File.join(base_path, 'models', "#{template}.rb")
49
+ end
50
+
35
51
  def template
36
52
  params['template']
37
53
  end
@@ -60,10 +76,6 @@ module Alephant
60
76
  @parser ||= Parser.new
61
77
  end
62
78
 
63
- def base_path
64
- "#{Dir.pwd}/components"
65
- end
66
-
67
79
  def fixture_location
68
80
  "#{base_path}/#{id}/fixtures/#{fixture}.json"
69
81
  end
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Preview
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-preview
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
  - Robert Kenny
@@ -207,7 +207,7 @@ dependencies:
207
207
  prerelease: false
208
208
  type: :runtime
209
209
  - !ruby/object:Gem::Dependency
210
- name: alephant
210
+ name: alephant-renderer
211
211
  version_requirements: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - '>='