great_pretender 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +6 -1
- data/README.md +2 -0
- data/app/helpers/great_pretender/mockups_helper.rb +2 -0
- data/lib/great_pretender/controller.rb +0 -1
- data/lib/great_pretender/mockup.rb +1 -1
- data/lib/great_pretender/mockup_locator.rb +17 -9
- data/lib/great_pretender/pretender.rb +4 -3
- data/lib/great_pretender/version.rb +1 -1
- data/spec/controllers/great_pretender/mockups_controller_spec.rb +7 -0
- data/spec/lib/great_pretender/config_spec.rb +2 -0
- data/spec/lib/great_pretender/mockup_locator_spec.rb +2 -0
- data/spec/lib/great_pretender/mockup_spec.rb +11 -2
- data/spec/lib/great_pretender/pretender_spec.rb +34 -1
- data/spec/spec_helper.rb +9 -0
- data/spec/support/mockup_helpers.rb +4 -11
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be13699344821526b0f5bb5bd0be76401d32b24f
|
4
|
+
data.tar.gz: d7f7f6e97097818c566be9ab78cd6a7226f7fa12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d4a07e77ef31ff590cda5c8fe437a1ed28d894424b0d95309bdf870903264d05f061a6c8e81a1409da48930117d26ef73898e96c74cc1d2e658d8befdfb6c87
|
7
|
+
data.tar.gz: a4c3842bd70ab69c3953223b79cf9723c1814e6c316ccc81dfcd47a849d13b45354f79fe9aa38f5f35015ae7c17ba4e4cbb6aee8b2a3355c50e34a809731efc7
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Code Climate](https://codeclimate.com/github/BackForty/great_pretender/badges/gpa.svg)](https://codeclimate.com/github/BackForty/great_pretender) [![Test Coverage](https://codeclimate.com/github/BackForty/great_pretender/badges/coverage.svg)](https://codeclimate.com/github/BackForty/great_pretender)
|
2
|
+
|
1
3
|
# Great Pretender
|
2
4
|
|
3
5
|
**Ridiculously easy-to-use Rails mockups for those enlightened individuals who design in-browser.**
|
@@ -14,15 +14,7 @@ module GreatPretender
|
|
14
14
|
return @mockups if defined? @mockups
|
15
15
|
mockups = []
|
16
16
|
@view_paths.each do |view_path|
|
17
|
-
|
18
|
-
templates = Dir[root.join("**/*.#{extensions}")]
|
19
|
-
templates.each do |path|
|
20
|
-
mockup = Mockup.new(path)
|
21
|
-
mockup.slug = slug_for(root, path)
|
22
|
-
mockup.layout = layout_for(mockup.slug)
|
23
|
-
mockup.template = template_for(view_path, root, mockup.slug)
|
24
|
-
mockups.push(mockup)
|
25
|
-
end
|
17
|
+
mockups.push(*mockups_for(view_path))
|
26
18
|
end
|
27
19
|
@mockups = mockups
|
28
20
|
end
|
@@ -69,6 +61,22 @@ module GreatPretender
|
|
69
61
|
end
|
70
62
|
end
|
71
63
|
|
64
|
+
def mockup_for(view_path, root, path)
|
65
|
+
mockup = Mockup.new(path)
|
66
|
+
mockup.slug = slug_for(root, path)
|
67
|
+
mockup.layout = layout_for(mockup.slug)
|
68
|
+
mockup.template = template_for(view_path, root, mockup.slug)
|
69
|
+
mockup
|
70
|
+
end
|
71
|
+
|
72
|
+
def mockups_for(view_path)
|
73
|
+
root = view_path.join(GreatPretender.config.view_path)
|
74
|
+
templates = Dir[root.join("**/*.#{extensions}")]
|
75
|
+
templates.map do |path|
|
76
|
+
mockup_for(view_path, root, path)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
72
80
|
def slug_for(root, path)
|
73
81
|
slug = path.to_s.gsub(%r{^#{root.to_s}/}, '')
|
74
82
|
while (ext = File.extname(slug)).length > 0
|
@@ -47,9 +47,10 @@ module GreatPretender
|
|
47
47
|
@mockup.slug.split("/").each do |pretender_name|
|
48
48
|
# Given a mockup named something like 'social_contents',
|
49
49
|
# support pretenders named 'SocialContentsPretender' AND 'SocialContentPretender'
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
singular_class = pretender_name.classify
|
51
|
+
plural_class = singular_class.pluralize
|
52
|
+
|
53
|
+
[singular_class, plural_class].each do |class_name|
|
53
54
|
if instance = load_pretender(class_name)
|
54
55
|
pretenders.push(instance)
|
55
56
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
1
3
|
require 'great_pretender/mockup'
|
2
4
|
require_relative '../../support/mockup_helpers'
|
3
5
|
|
@@ -6,9 +8,16 @@ describe GreatPretender::Mockup do
|
|
6
8
|
include MockupHelpers
|
7
9
|
|
8
10
|
let(:mockup) { mockup_locator.mockups.find {|m| m.slug =~ /admin/ } }
|
11
|
+
let(:partial) { mockup_locator.mockups.find {|m| m.slug =~ /^_/ } }
|
12
|
+
|
13
|
+
context ".name" do
|
14
|
+
it "returns a human-readable name from its slug" do
|
15
|
+
expect(mockup.name).to eq("Admin > Index")
|
16
|
+
end
|
9
17
|
|
10
|
-
|
11
|
-
|
18
|
+
it "marks a partial as such" do
|
19
|
+
expect(partial.name).to eq("Partial (partial)")
|
20
|
+
end
|
12
21
|
end
|
13
22
|
|
14
23
|
context ".to_param" do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
1
3
|
require 'great_pretender/pretender'
|
2
4
|
require 'ostruct'
|
3
5
|
|
@@ -5,12 +7,26 @@ class PrefixSlugPretender
|
|
5
7
|
def say_hello
|
6
8
|
"Hello, guest!"
|
7
9
|
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
"Flip"
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
|
-
class
|
16
|
+
class TestSlugsPretender
|
17
|
+
attr_reader :mockup
|
18
|
+
|
19
|
+
def initialize(mockup)
|
20
|
+
@mockup = mockup
|
21
|
+
end
|
22
|
+
|
11
23
|
def ohai
|
12
24
|
"ohai"
|
13
25
|
end
|
26
|
+
|
27
|
+
def name
|
28
|
+
"Avery"
|
29
|
+
end
|
14
30
|
end
|
15
31
|
|
16
32
|
describe GreatPretender::Pretender do
|
@@ -30,4 +46,21 @@ describe GreatPretender::Pretender do
|
|
30
46
|
expect(recipient.say_hello).to eq("Hello, guest!")
|
31
47
|
end
|
32
48
|
|
49
|
+
it "delegates methods to the most specific responder" do
|
50
|
+
expect(recipient.name).to eq("Avery")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "passes the mockup to pretenders that accept an initialization argument" do
|
54
|
+
expect(TestSlugsPretender).to receive(:new).with(mockup)
|
55
|
+
recipient
|
56
|
+
end
|
57
|
+
|
58
|
+
it "correctly calls super when a method doesn't exist" do
|
59
|
+
expect(-> { recipient.foobar }).to raise_error(NoMethodError)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "quietly flunks mockups without pretenders" do
|
63
|
+
pretenderless_mockup = OpenStruct.new(slug: "no_pretender_mockup")
|
64
|
+
expect(-> { GreatPretender::Pretender.new(pretenderless_mockup) } ).not_to raise_error
|
65
|
+
end
|
33
66
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
|
1
3
|
module MockupHelpers
|
2
4
|
def self.included(base)
|
3
5
|
base.class_eval do
|
@@ -5,7 +7,8 @@ module MockupHelpers
|
|
5
7
|
let(:paths) do
|
6
8
|
[
|
7
9
|
Pathname.new("spec/fixtures/view_path_a").expand_path,
|
8
|
-
|
10
|
+
OpenStruct.new(to_path: "spec/fixtures/view_path_b"),
|
11
|
+
OpenStruct.new(to_s: "spec/fixtures/view_path_c")
|
9
12
|
]
|
10
13
|
end
|
11
14
|
|
@@ -13,14 +16,4 @@ module MockupHelpers
|
|
13
16
|
|
14
17
|
end
|
15
18
|
end
|
16
|
-
|
17
|
-
class Stub
|
18
|
-
def initialize(path)
|
19
|
-
@path = path
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_path
|
23
|
-
@path.to_s
|
24
|
-
end
|
25
|
-
end
|
26
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: great_pretender
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flip Sasser
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/great_pretender/mockup_locator.rb
|
68
68
|
- lib/great_pretender/pretender.rb
|
69
69
|
- lib/great_pretender/version.rb
|
70
|
+
- spec/controllers/great_pretender/mockups_controller_spec.rb
|
70
71
|
- spec/fixtures/view_path_a/.DS_Store
|
71
72
|
- spec/fixtures/view_path_a/layouts/admin.html.slim
|
72
73
|
- spec/fixtures/view_path_a/mockups/_partial.haml
|
@@ -78,6 +79,7 @@ files:
|
|
78
79
|
- spec/lib/great_pretender/mockup_locator_spec.rb
|
79
80
|
- spec/lib/great_pretender/mockup_spec.rb
|
80
81
|
- spec/lib/great_pretender/pretender_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
81
83
|
- spec/support/mockup_helpers.rb
|
82
84
|
homepage: https://github.com/BackForty/great_pretender
|
83
85
|
licenses:
|
@@ -105,6 +107,7 @@ specification_version: 4
|
|
105
107
|
summary: Ridiculously easy-to-use Rails mockups for those enlightened individuals
|
106
108
|
who design in-browser
|
107
109
|
test_files:
|
110
|
+
- spec/controllers/great_pretender/mockups_controller_spec.rb
|
108
111
|
- spec/fixtures/view_path_a/.DS_Store
|
109
112
|
- spec/fixtures/view_path_a/layouts/admin.html.slim
|
110
113
|
- spec/fixtures/view_path_a/mockups/_partial.haml
|
@@ -116,4 +119,5 @@ test_files:
|
|
116
119
|
- spec/lib/great_pretender/mockup_locator_spec.rb
|
117
120
|
- spec/lib/great_pretender/mockup_spec.rb
|
118
121
|
- spec/lib/great_pretender/pretender_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
119
123
|
- spec/support/mockup_helpers.rb
|