great_pretender 0.1.4 → 0.2.0

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
- SHA1:
3
- metadata.gz: eb62253be2761441bf8ea8afce272f260d2a2bb6
4
- data.tar.gz: 150374a364f75f88ef4d501e4c8aae17d4314c1c
2
+ SHA256:
3
+ metadata.gz: 7b0e378c0f00624232fc1ce26fb82fd0ddc54741434d198d93e3b8d9fe15bbb2
4
+ data.tar.gz: 4577baa21f8a73b61afbad15fbe2c8ecaf66224e52cac0b8f860ff28459b6018
5
5
  SHA512:
6
- metadata.gz: 2e93f794863f798c0acd61d114bb702f1324d9986e3e29b71cf7a4f9a49071b9b0b5b3db168d346b4d223042d77ac2bb27cc0ab9a3ba3c40b489b284e41199db
7
- data.tar.gz: a71df485d09157758175644eea9485ca2ff02e6dd50179dc5771b3bbbf85ddfa9a59fd9d7399193f5338e1f4bd589b55b2af03ffce024c3eb6d17034ab2c88d7
6
+ metadata.gz: 7862990ed9cf842ae00e97cd2fb6a43305210abd6e871169ded5d14fed1809f9b024cdd168f721016951907145702fab20d18b0ca183f45b1df8f428129ca29b
7
+ data.tar.gz: acf2e01cfd5ee083b2f814b11689e8900e0a3dc4493237b82ca4e17b6f3c032f505243515aed797d1af08fce07b075d0bab7edf4a79620bc434346a2c8ea2658
data/.rubocop.yml ADDED
@@ -0,0 +1,184 @@
1
+ require:
2
+ - rubocop-ordered_methods
3
+ - rubocop-performance
4
+ - rubocop-rails
5
+ - rubocop-rspec
6
+ - rubocop-rails
7
+ - standard
8
+
9
+ inherit_gem:
10
+ rubocop-ordered_methods:
11
+ - config/default.yml
12
+ rubocop-performance:
13
+ - config/default.yml
14
+ rubocop-rails:
15
+ - config/default.yml
16
+ rubocop-rspec:
17
+ - config/default.yml
18
+ standard:
19
+ - config/ruby-2.7.yml
20
+
21
+ AllCops:
22
+ TargetRubyVersion: 2.7.6
23
+ NewCops: enable
24
+ Exclude:
25
+ - "bin/**/*"
26
+ - "coverage/**/*"
27
+ - "db/migrate/*"
28
+ - "db/schema.rb"
29
+ - "lib/enum_migration.rb"
30
+ - "log/**/*"
31
+ - "node_modules/**/*"
32
+ - "public/**/*"
33
+ - "tmp/**/*"
34
+ - "vendor/**/*"
35
+
36
+ Layout/FirstHashElementLineBreak:
37
+ Enabled: true
38
+
39
+ Layout/FirstMethodArgumentLineBreak:
40
+ Enabled: true
41
+
42
+ Layout/HashAlignment:
43
+ Enabled: true
44
+ EnforcedHashRocketStyle: table
45
+ EnforcedColonStyle: table
46
+ EnforcedLastArgumentHashStyle: always_inspect
47
+
48
+ Layout/MultilineArrayLineBreaks:
49
+ Enabled: true
50
+
51
+ Layout/MultilineArrayBraceLayout:
52
+ Enabled: true
53
+ EnforcedStyle: symmetrical
54
+
55
+ Layout/MultilineHashBraceLayout:
56
+ Enabled: true
57
+ EnforcedStyle: new_line
58
+
59
+ Layout/MultilineMethodCallBraceLayout:
60
+ Enabled: true
61
+ EnforcedStyle: new_line
62
+
63
+ Layout/MultilineHashKeyLineBreaks:
64
+ Enabled: true
65
+
66
+ Layout/MultilineMethodArgumentLineBreaks:
67
+ Enabled: true
68
+
69
+ Layout/ParameterAlignment:
70
+ Enabled: true
71
+ EnforcedStyle: with_fixed_indentation
72
+
73
+ Layout/RescueEnsureAlignment:
74
+ Enabled: false
75
+
76
+ Lint/AssignmentInCondition:
77
+ Enabled: false
78
+
79
+ # Yo ... `to_i` is gonna have to suffice for now because `Integer(possibly_nil, 10)` explodes, like,
80
+ # all the time
81
+ Lint/NumberConversion:
82
+ Enabled: false
83
+
84
+ Rails/DynamicFindBy:
85
+ Enabled: true
86
+ AllowedMethods:
87
+ - find_by_short_id
88
+ - find_by_slug # Generated by Slugify fairly often
89
+ - find_by_slug! # Samesies
90
+ - find_by_variant_slug
91
+
92
+ Rails/FilePath:
93
+ EnforcedStyle: arguments
94
+
95
+ Rails/HasAndBelongsToMany:
96
+ Enabled: false
97
+
98
+ Rails/RakeEnvironment:
99
+ Enabled: false
100
+
101
+ Rails/SkipsModelValidations:
102
+ Enabled: false
103
+
104
+ Rails/UnknownEnv:
105
+ Enabled: true
106
+ Environments:
107
+ - development
108
+ - test
109
+ - production
110
+ - staging
111
+
112
+ RSpec/Capybara/FeatureMethods:
113
+ Enabled: true
114
+ EnabledMethods:
115
+ - scenario
116
+
117
+ RSpec/ContextWording:
118
+ Enabled: false
119
+
120
+ RSpec/DescribeClass:
121
+ Enabled: true
122
+ Exclude:
123
+ - spec/system/**/*
124
+
125
+ RSpec/Dialect:
126
+ Enabled: false
127
+ # PreferredMethods:
128
+ # context: describe
129
+
130
+ RSpec/ExampleLength:
131
+ # Reasoning here is that, let's be honest, this is arbitrary AF. If the specs get out of control,
132
+ # we'll switch it back on and figure something out. Until then, when you're running assertions
133
+ # against large multi-line hashes, I'd rather have it be readable rather than arbitrarily short.
134
+ Enabled: false
135
+
136
+ RSpec/Focus:
137
+ AutoCorrect: false
138
+ Enabled: true
139
+
140
+ RSpec/MultipleExpectations:
141
+ Exclude:
142
+ - spec/controllers/**/*
143
+ - spec/system/**/*
144
+ Max: 6
145
+
146
+ RSpec/MultipleMemoizedHelpers:
147
+ Enabled: true
148
+ Exclude:
149
+ - spec/system/**/*
150
+ Max: 8
151
+
152
+ RSpec/NestedGroups:
153
+ Max: 5 # TODO: lower this again someday, but AFTER we pull the letter logic
154
+
155
+ RSpec/SharedExamples:
156
+ Enabled: false
157
+
158
+ Style/FrozenStringLiteralComment:
159
+ AutoCorrect: true
160
+ Enabled: true
161
+ Exclude:
162
+ - db/data_schema.rb
163
+
164
+ Style/MissingRespondToMissing:
165
+ Enabled: false # TODO: I dunno; maybe we do this. But for right now it's a pain in the neck
166
+
167
+ Style/StringLiterals:
168
+ EnforcedStyle: double_quotes
169
+ Enabled: true
170
+
171
+ Style/SymbolArray:
172
+ Enabled: true
173
+
174
+ Style/TrailingCommaInArguments:
175
+ EnforcedStyleForMultiline: comma
176
+
177
+ Style/TrailingCommaInArrayLiteral:
178
+ EnforcedStyleForMultiline: comma
179
+
180
+ Style/TrailingCommaInHashLiteral:
181
+ EnforcedStyleForMultiline: comma
182
+
183
+ Style/WordArray:
184
+ Enabled: true
data/Gemfile CHANGED
@@ -1,10 +1,19 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ ruby "2.7.6"
2
6
 
3
7
  # Specify your gem's dependencies in great_pretender.gemspec
4
8
  gemspec
5
9
 
6
10
  group :test do
7
- gem "rspec-rails"
8
11
  gem "codeclimate-test-reporter", require: false
12
+ gem "rubocop", require: false
13
+ gem "rubocop-ordered_methods", require: false
14
+ gem "rubocop-performance", require: false
15
+ gem "rubocop-rails", require: false
16
+ gem "rubocop-rspec", require: false
9
17
  gem "simplecov", require: false
18
+ gem "standard", ">= 1.0", require: false
10
19
  end
data/README.md CHANGED
@@ -15,7 +15,6 @@
15
15
  - Installs in 2 minutes as a Rails engine
16
16
  - Can be mixed in to other controllers for access control or whatever else you want to add
17
17
  - Configurable mockups folder name and default layout
18
- - Dances with wolves
19
18
 
20
19
  ## Install
21
20
 
@@ -75,13 +74,10 @@ If that's the case, you can create your own controller that uses Great Pretender
75
74
 
76
75
  ```ruby
77
76
  class Admin::MockupsController < Admin::ApplicationController
78
-
79
77
  include GreatPretender::Controller
80
78
 
81
79
  before_action :require_admin_user! # or whatever
82
-
83
80
  layout 'admin' # or whatever
84
-
85
81
  end
86
82
  ```
87
83
 
@@ -163,13 +159,23 @@ A lot of the time you'll want to emulate real data in your views. In those cases
163
159
 
164
160
  Pretender objects can be any class. They can accept a single argument in `initialize`, which will be the the mockup being rendered, **or** they can skip it entirely.
165
161
 
166
- Any public method you add to a pretender object will be available to the view, just like helper methods.
162
+ An instance of every pretender will be available inside your templates. So for, e.g., a `user_pretender.rb` that defines:
167
163
 
168
- ### Load order
164
+ ```
165
+ class UserPretender
166
+ def name
167
+ "Gary Sinese"
168
+ end
169
+ end
170
+ ```
169
171
 
170
- Pretenders, like layouts, are loaded based on the name of your mockup file. For example, a mockup named "users/login" would look for `app/pretenders/user(s)_pretender.rb` and `app/pretenders/login_pretender.rb`. **Please note** that plurally named templates will support a singular pretender, but singularly named templates will only load singular pretenders.
172
+ You would reference a `user` helper method (or `user_pretender` if `user` is already defined):
171
173
 
172
- Pretenders are delegated to in order of most specific (`LoginPretender`) to least specific (`UserPretender`). So if `LoginPretender` and `UserPretender` both define method `name`, the `LoginPretender`'s implementation will be used.
174
+ ```erb
175
+ <%= user.name %> <!-- Outputs "Gary Sinese" -->
176
+ or
177
+ <%= user_pretender.name %> <!-- Outputs same -->
178
+ ```
173
179
 
174
180
  ### Example
175
181
 
@@ -181,7 +187,6 @@ Here's an example using the excellent [Faker gem](https://github.com/stympy/fake
181
187
  require "faker"
182
188
 
183
189
  class UserPretender
184
-
185
190
  def login
186
191
  Faker::Internet.user_name
187
192
  end
@@ -189,7 +194,6 @@ class UserPretender
189
194
  def email
190
195
  Faker::Internet.email
191
196
  end
192
-
193
197
  end
194
198
  ```
195
199
 
@@ -198,13 +202,12 @@ end
198
202
 
199
203
  ```slim
200
204
  header
201
- | Welome back, #{login}!
202
- | Your email is set to #{email}
205
+ | Welome back, #{user.login}!
206
+ | Your email is set to #{user.email}
203
207
 
204
208
  / The remainder of your login form mockup...
205
209
  ```
206
210
 
207
-
208
211
  ## The end!
209
212
 
210
213
  Thanks for using Great Pretender! I hope it helps you like it's helped us!
data/Rakefile CHANGED
@@ -1,2 +1,3 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
2
 
3
+ require "bundler/gem_tasks"
@@ -1,9 +1,9 @@
1
- require 'great_pretender/controller'
1
+ # frozen_string_literal: true
2
+
3
+ require "great_pretender/controller"
2
4
 
3
5
  module GreatPretender
4
6
  class MockupsController < GreatPretender.config.base_controller
5
-
6
7
  include GreatPretender::Controller
7
-
8
8
  end
9
9
  end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GreatPretender
2
4
  module MockupsHelper
3
-
4
5
  def great_pretender_mockup_path(mockup)
5
6
  if controller.is_a?(GreatPretender::MockupsController)
6
7
  great_pretender_engine.mockup_path(mockup)
@@ -8,24 +9,43 @@ module GreatPretender
8
9
  path_helper = controller_path.split("/")
9
10
  path_helper = path_helper.join("_")
10
11
  path_helper = path_helper.singularize
11
- path_helper << '_url'
12
+ path_helper << "_url"
12
13
  begin
13
14
  send(path_helper, mockup)
14
- rescue NoMethodError => error
15
+ rescue NoMethodError => e
15
16
  error_message_subs = [controller_path, path_helper]
16
- error_message = I18n.t('great_pretender.missing_helper_methods') % error_message_subs
17
- raise MissingPathHelperError.new(error_message, error)
17
+ error_message = I18n.t("great_pretender.missing_helper_methods") % error_message_subs
18
+ raise MissingPathHelperError.new(error_message, e)
18
19
  end
19
20
  end
20
21
  end
21
22
 
23
+ private
24
+
25
+ # Trap calls to pretenders' names
26
+ def method_missing(name, *args, &block)
27
+ prefix = name.to_s.chomp("_pretender")
28
+ if args.empty? && !block && (class_name = "#{prefix.classify}Pretender").safe_constantize
29
+ class_eval <<-EOM, __FILE__, __LINE__ + 1
30
+ def #{prefix}
31
+ @great_pretender_pretender_#{prefix} ||= begin
32
+ init = #{class_name}.instance_method(:initialize)
33
+ init.arity == 1 ? #{class_name}.new(mockup) : #{class_name}.new
34
+ end
35
+ end
36
+ EOM
37
+
38
+ return send(prefix)
39
+ end
40
+
41
+ super
42
+ end
22
43
  end
23
44
 
24
45
  class MissingPathHelperError < StandardError
25
46
  def initialize(message, error)
26
47
  super(message)
27
- @original_error = error
48
+ @original_error = error # rubocop:disable Rails/HelperInstanceVariable
28
49
  end
29
50
  end
30
-
31
51
  end
@@ -0,0 +1,29 @@
1
+ <% if mockup_locator.mockups.any? %>
2
+ <table id="mockups">
3
+ <thead>
4
+ <tr>
5
+ <th>Template</th>
6
+ <th>Last Updated</th>
7
+ </tr>
8
+ </thead>
9
+ <tbody>
10
+ <% mockup_locator.mockups.each do |mockup| %>
11
+ <tr>
12
+ <td>
13
+ <strong>
14
+ <%= link_to mockup.name, great_pretender_mockup_path(mockup) %>
15
+ </strong>
16
+ </td>
17
+ <td>
18
+ <%= time_ago_in_words(mockup.updated_at) %> ago
19
+ </td>
20
+ </tr>
21
+ <% end %>
22
+ </tbody>
23
+ </table>
24
+ <% else %>
25
+ <p>
26
+ No mockups found. Add a template file to <code><%= mockup_root %></code> to
27
+ see it listed here.
28
+ </p>
29
+ <% end %>
@@ -1,30 +1 @@
1
- <% if mockups.any? %>
2
- <table id="mockups">
3
- <thead>
4
- <tr>
5
- <th>Template</th>
6
- <th>Last Updated</th>
7
- </tr>
8
- </thead>
9
- <tbody>
10
- <% mockups.each do |mockup| %>
11
- <tr>
12
- <td>
13
- <strong>
14
- <%= link_to mockup.name, great_pretender_mockup_path(mockup) %>
15
- </strong>
16
- </td>
17
- <td>
18
- <%= time_ago_in_words(mockup.updated_at) %> ago
19
- </td>
20
- </tr>
21
- <% end %>
22
- </tbody>
23
- </table>
24
- <% else %>
25
- <p>
26
- No mockups found. Add a template file to <code><%= mockup_root %></code> to
27
- see it listed here.
28
- </p>
29
- <% end %>
30
-
1
+ <%= render "/great_pretender/index" %>
data/config/routes.rb CHANGED
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  GreatPretender::Engine.routes.draw do
2
- root to: 'great_pretender/mockups#index', as: :mockups
3
- get '*id', to: 'great_pretender/mockups#show', as: :mockup
4
+ root to: "great_pretender/mockups#index", as: :mockups
5
+ get "*id", to: "great_pretender/mockups#show", as: :mockup
4
6
  end
@@ -1,23 +1,23 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'great_pretender/version'
5
+ require "great_pretender/version"
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "great_pretender"
8
- spec.version = GreatPretender::VERSION
9
- spec.authors = ["Flip Sasser"]
10
- spec.email = ["flip@inthebackforty.com"]
11
- spec.summary = %q{Ridiculously easy-to-use Rails mockups for those enlightened individuals who design in-browser}
12
- spec.description = %q{Use Great Pretender to easily add layout-specific mockups in a Rails app without having to recreate the mockup wheel. Your design should be happening in-browser; this will help you get there.}
13
- spec.homepage = "https://github.com/BackForty/great_pretender"
14
- spec.license = "MIT"
8
+ spec.name = "great_pretender"
9
+ spec.version = GreatPretender::VERSION
10
+ spec.authors = ["Flip Sasser"]
11
+ spec.email = ["flip@inthebackforty.com"]
12
+ spec.summary = "Ridiculously easy-to-use Rails mockups for those enlightened individuals who design in-browser"
13
+ spec.description = "Use Great Pretender to easily add layout-specific mockups in a Rails app without having to recreate the mockup wheel. Your design should be happening in-browser; this will help you get there."
14
+ spec.homepage = "https://github.com/BackForty/great_pretender"
15
+ spec.license = "MIT"
15
16
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "bundler", "~> 2.3"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  end
@@ -1,14 +1,17 @@
1
- module GreatPretender
1
+ # frozen_string_literal: true
2
2
 
3
+ module GreatPretender
3
4
  class Config
4
-
5
5
  attr_accessor :default_layout, :path_separator, :view_path
6
- attr_writer :base_controller
7
6
 
8
7
  def base_controller
9
- @base_controller ||= ::ApplicationController
8
+ @base_controller ||= "::ApplicationController"
9
+ @base_controller.constantize
10
10
  end
11
11
 
12
+ def base_controller=(new_base_controller)
13
+ @base_controller = new_base_controller.to_s
14
+ end
12
15
  end
13
16
 
14
17
  def self.config
@@ -18,11 +21,10 @@ module GreatPretender
18
21
  end
19
22
  @config
20
23
  end
21
-
22
24
  end
23
25
 
24
26
  GreatPretender.config do |c|
25
- c.default_layout = 'application'
26
- c.path_separator = ' > '
27
- c.view_path = 'mockups'
27
+ c.default_layout = "application"
28
+ c.path_separator = " > "
29
+ c.view_path = "mockups"
28
30
  end
@@ -1,24 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "great_pretender/mockup_locator"
2
- require "great_pretender/pretender"
3
4
 
4
5
  module GreatPretender
5
6
  module Controller
6
-
7
7
  def self.included(base)
8
- base.helper_method :mockups
9
- base.helper_method :mockup_root
10
8
  base.helper GreatPretender::MockupsHelper
9
+ base.helper_method :mockup_locator
10
+ base.helper_method :mockup_root
11
11
  end
12
12
 
13
13
  def index
14
- render template: 'great_pretender/index', layout: GreatPretender.config.default_layout
14
+ render template: "great_pretender/index", layout: GreatPretender.config.default_layout
15
15
  end
16
16
 
17
17
  def show
18
18
  if mockup
19
19
  render template: mockup.template, layout: mockup.layout
20
20
  else
21
- error_message = I18n.t('great_pretender.not_found') % params[:id]
21
+ error_message = I18n.t("great_pretender.not_found") % params[:id]
22
22
  raise ActiveRecord::RecordNotFound.new(error_message)
23
23
  end
24
24
  end
@@ -26,11 +26,8 @@ module GreatPretender
26
26
  private
27
27
 
28
28
  def mockup
29
- @great_pretender_mockup ||= mockup_locator.find(params[:id])
30
- end
31
-
32
- def mockups
33
- @great_pretender_mockups ||= mockup_locator.mockups
29
+ return @great_pretender_mockup if defined? @great_pretender_mockup
30
+ @great_pretender_mockup = mockup_locator.find(params[:id])
34
31
  end
35
32
 
36
33
  def mockup_locator
@@ -40,16 +37,5 @@ module GreatPretender
40
37
  def mockup_root
41
38
  @great_pretender_mockup_root ||= mockup_locator.view_paths.first.join(GreatPretender.config.view_path)
42
39
  end
43
-
44
- def pretender
45
- @great_pretender_pretender ||= Pretender.new(mockup)
46
- end
47
-
48
- def view_context
49
- super.tap do |view_context|
50
- view_context.extend pretender.to_module if mockup
51
- end
52
- end
53
-
54
40
  end
55
41
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GreatPretender
2
4
  class Engine < ::Rails::Engine
3
5
  config.generators do |g|
4
6
  g.test_framework :rspec
5
7
  end
6
8
 
7
- config.autoload_paths.push(Pathname.new('').join('app', 'pretenders').expand_path.to_s)
9
+ config.autoload_paths.push(Pathname.new("").join("app", "pretenders").expand_path.to_s)
8
10
  end
9
11
  end
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/string/inflections"
2
4
  require "great_pretender/config"
3
5
 
4
6
  module GreatPretender
5
7
  class Mockup
6
-
7
8
  attr_accessor :layout, :path, :slug, :template
8
9
 
9
- alias :to_param :slug
10
+ alias_method :to_param, :slug
10
11
 
11
12
  def initialize(path)
12
13
  @file = Pathname.new(path)
@@ -14,9 +15,9 @@ module GreatPretender
14
15
 
15
16
  def name
16
17
  return @name if defined? @name
17
- name = slug.split('/').map { |s| s.titleize }.join(GreatPretender.config.path_separator)
18
- if slug =~ /^_/
19
- name << ' (partial)'
18
+ name = slug.split("/").map { |s| s.titleize }.join(GreatPretender.config.path_separator)
19
+ if /^_/.match?(slug)
20
+ name << " (partial)"
20
21
  end
21
22
  @name = name.strip
22
23
  end
@@ -24,6 +25,5 @@ module GreatPretender
24
25
  def updated_at
25
26
  @file.mtime
26
27
  end
27
-
28
28
  end
29
29
  end
@@ -1,13 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "great_pretender/config"
2
4
  require "great_pretender/mockup"
3
5
 
4
6
  module GreatPretender
5
7
  class MockupLocator
6
-
7
8
  attr_reader :view_paths
8
9
 
9
10
  def find(slug)
10
- mockups.find {|mockup| mockup.slug == slug}
11
+ mockups.find { |mockup| mockup.slug == slug }
11
12
  end
12
13
 
13
14
  def mockups
@@ -36,12 +37,12 @@ module GreatPretender
36
37
  def extensions
37
38
  return @extensions if defined? @extensions
38
39
  extensions = ActionView::Template.template_handler_extensions
39
- extensions = extensions.map(&:to_s).join(',')
40
+ extensions = extensions.map(&:to_s).join(",")
40
41
  @extensions = "{#{extensions}}"
41
42
  end
42
43
 
43
44
  def layout_for(slug)
44
- if File.basename(slug) =~ /^_/
45
+ if /^_/.match?(File.basename(slug))
45
46
  # Partials (named like "_template_name") don't render inside a layout.
46
47
  # This way they can be used w/Ajax requests, etc.
47
48
  nil
@@ -49,12 +50,12 @@ module GreatPretender
49
50
  # Mockups can have a layout by being in a folder named after that
50
51
  # layout; for example, "app/views/mockups/admin/index" will look for an
51
52
  # "admin" template
52
- layout = slug.split('/')
53
+ layout = slug.split("/")
53
54
  layout.pop
54
- layout = layout.join('/')
55
+ layout = layout.join("/")
55
56
  if layout && layout.length > 0
56
57
  @view_paths.each do |view_path|
57
- layout_path = view_path.join('layouts')
58
+ layout_path = view_path.join("layouts")
58
59
  layout_path = layout_path.join("#{layout}.*#{extensions}")
59
60
  return layout if Dir[layout_path].any?
60
61
  end
@@ -64,9 +65,12 @@ module GreatPretender
64
65
  end
65
66
 
66
67
  def mockup_for(view_path, root, path)
68
+ slug = slug_for(root, path)
69
+ return if slug == "index" # Don't render an index wireframe at the root of our wireframes folder
70
+
67
71
  mockup = Mockup.new(path)
68
72
  mockup.path = path
69
- mockup.slug = slug_for(root, path)
73
+ mockup.slug = slug
70
74
  mockup.layout = layout_for(mockup.slug)
71
75
  mockup.template = template_for(view_path, root, mockup.slug)
72
76
  mockup
@@ -75,15 +79,15 @@ module GreatPretender
75
79
  def mockups_for(view_path)
76
80
  root = view_path.join(GreatPretender.config.view_path)
77
81
  templates = Dir[root.join("**/*.#{extensions}")]
78
- templates.map do |path|
82
+ templates.filter_map do |path|
79
83
  mockup_for(view_path, root, path)
80
84
  end
81
85
  end
82
86
 
83
87
  def slug_for(root, path)
84
- slug = path.to_s.gsub(%r{^#{root.to_s}/}, '')
88
+ slug = path.to_s.gsub(%r{^#{root}/}, "")
85
89
  while (ext = File.extname(slug)).length > 0
86
- slug = slug.gsub(/#{ext}$/, '')
90
+ slug = slug.gsub(/#{ext}$/, "")
87
91
  end
88
92
  slug
89
93
  end
@@ -92,6 +96,5 @@ module GreatPretender
92
96
  template_root = root.relative_path_from(view_path)
93
97
  template_root.join(slug).to_s
94
98
  end
95
-
96
99
  end
97
100
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GreatPretender
2
- VERSION = "0.1.4"
4
+ VERSION = "0.2.0"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "great_pretender/config"
2
4
  require "great_pretender/controller"
3
5
  require "great_pretender/version"
@@ -1,7 +1,9 @@
1
- require 'spec_helper'
2
- #require 'rspec/rails'
3
- #require 'great_pretender/mockups_controller'
1
+ # frozen_string_literal: true
4
2
 
5
- #describe GreatPretender::MockupsController do
3
+ require "spec_helper"
4
+ # require 'rspec/rails'
5
+ # require 'great_pretender/mockups_controller'
6
6
 
7
- #end
7
+ # describe GreatPretender::MockupsController do
8
+
9
+ # end
@@ -1,39 +1,35 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  module GreatPretender; end
4
6
 
5
7
  describe GreatPretender do
6
-
7
- context ".config" do
8
-
8
+ describe ".config" do
9
9
  before { load("great_pretender/config.rb") }
10
10
 
11
11
  context "default configuration values" do
12
-
13
12
  it "has 'application' as the default layout" do
14
- expect(GreatPretender.config.default_layout).to eq("application")
13
+ expect(described_class.config.default_layout).to eq("application")
15
14
  end
16
15
 
17
16
  it "has 'mockups' as the default view path" do
18
- expect(GreatPretender.config.view_path).to eq("mockups")
17
+ expect(described_class.config.view_path).to eq("mockups")
19
18
  end
20
-
21
19
  end
22
20
 
23
21
  it "accepts a block" do
24
- GreatPretender.config do |c|
22
+ described_class.config do |c|
25
23
  c.default_layout = "another_layout"
26
24
  c.view_path = "somewhere"
27
25
  end
28
- expect(GreatPretender.config.default_layout).to eq("another_layout")
29
- expect(GreatPretender.config.view_path).to eq("somewhere")
26
+ expect(described_class.config.default_layout).to eq("another_layout")
27
+ expect(described_class.config.view_path).to eq("somewhere")
30
28
  end
31
29
 
32
30
  it "can be used for direct setting of configuration options" do
33
- GreatPretender.config.default_layout = "a_third_layout"
34
- expect(GreatPretender.config.default_layout).to eq("a_third_layout")
31
+ described_class.config.default_layout = "a_third_layout"
32
+ expect(described_class.config.default_layout).to eq("a_third_layout")
35
33
  end
36
-
37
34
  end
38
-
39
35
  end
@@ -1,25 +1,26 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- require 'great_pretender/mockup_locator'
4
- require 'pathname'
5
- require_relative '../../support/mockup_helpers'
3
+ require "spec_helper"
4
+
5
+ require "great_pretender/mockup_locator"
6
+ require "pathname"
7
+ require_relative "../../support/mockup_helpers"
6
8
 
7
9
  module ActionView
8
10
  module Template
9
11
  def self.template_handler_extensions
10
- %w(erb slim haml)
12
+ %w[erb slim haml]
11
13
  end
12
14
  end
13
15
  end
14
16
 
15
17
  describe GreatPretender::MockupLocator do
16
-
17
18
  include MockupHelpers
18
19
 
19
- let(:regular_mockup) { mockup_locator.mockups.find {|m| m.slug =~ /^processed/ } }
20
- let(:partial_mockup) { mockup_locator.mockups.find {|m| m.slug =~ /^_/ } }
21
- let(:admin_mockup) { mockup_locator.mockups.find {|m| m.slug =~ /admin/ } }
22
- let(:nested_admin_mockup) { mockup_locator.mockups.find {|m| m.slug =~ /admin\/base/ } }
20
+ let(:regular_mockup) { mockup_locator.mockups.find { |m| m.slug =~ /^processed/ } }
21
+ let(:partial_mockup) { mockup_locator.mockups.find { |m| m.slug =~ /^_/ } }
22
+ let(:admin_mockup) { mockup_locator.mockups.find { |m| m.slug.include?("admin") } }
23
+ let(:nested_admin_mockup) { mockup_locator.mockups.find { |m| m.slug.include?("admin/base") } }
23
24
 
24
25
  context "::mockups" do
25
26
  it "returns all mockups in the pre-configured mockup directories" do
@@ -1,16 +1,17 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- require 'great_pretender/mockup'
4
- require_relative '../../support/mockup_helpers'
3
+ require "spec_helper"
5
4
 
6
- describe GreatPretender::Mockup do
5
+ require "great_pretender/mockup"
6
+ require_relative "../../support/mockup_helpers"
7
7
 
8
+ describe GreatPretender::Mockup do
8
9
  include MockupHelpers
9
10
 
10
- let(:mockup) { mockup_locator.mockups.find {|m| m.slug =~ /admin/ } }
11
- let(:partial) { mockup_locator.mockups.find {|m| m.slug =~ /^_/ } }
11
+ let(:mockup) { mockup_locator.mockups.find { |m| m.slug.include?("admin") } }
12
+ let(:partial) { mockup_locator.mockups.find { |m| m.slug =~ /^_/ } }
12
13
 
13
- context ".name" do
14
+ describe ".name" do
14
15
  it "returns a human-readable name from its slug" do
15
16
  expect(mockup.name).to eq("Admin > Index")
16
17
  end
@@ -20,17 +21,16 @@ describe GreatPretender::Mockup do
20
21
  end
21
22
  end
22
23
 
23
- context ".to_param" do
24
+ describe ".to_param" do
24
25
  it "returns the slug" do
25
26
  expect(mockup.to_param).to eq(mockup.slug)
26
27
  end
27
28
  end
28
29
 
29
- context ".updated_at" do
30
+ describe ".updated_at" do
30
31
  it "returns the template file's mtime for its slug" do
31
32
  `touch #{mockup.path}`
32
33
  expect(mockup.updated_at.to_i).to eq(Time.now.to_i)
33
34
  end
34
35
  end
35
-
36
36
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if ENV["CODECLIMATE_REPO_TOKEN"]
2
4
  require "codeclimate-test-reporter"
3
5
  CodeClimate::TestReporter.start
4
6
  else
5
7
  require "simplecov"
6
- SimpleCov.start do
7
- add_filter 'spec'
8
+ SimpleCov.start "rails" do
9
+ add_filter "spec"
8
10
  end
9
11
  end
@@ -1,19 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "ostruct"
2
4
 
3
5
  module MockupHelpers
4
6
  def self.included(base)
5
7
  base.class_eval do
6
-
7
8
  let(:paths) do
8
9
  [
9
10
  Pathname.new("spec/fixtures/view_path_a").expand_path,
10
11
  OpenStruct.new(to_path: "spec/fixtures/view_path_b"),
11
- OpenStruct.new(to_s: "spec/fixtures/view_path_c")
12
+ OpenStruct.new(to_s: "spec/fixtures/view_path_c"),
12
13
  ]
13
14
  end
14
15
 
15
16
  let(:mockup_locator) { GreatPretender::MockupLocator.new(paths) }
16
-
17
17
  end
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: great_pretender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flip Sasser
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-20 00:00:00.000000000 Z
11
+ date: 2022-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '2.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '2.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -49,12 +49,14 @@ extra_rdoc_files: []
49
49
  files:
50
50
  - ".gitignore"
51
51
  - ".rspec"
52
+ - ".rubocop.yml"
52
53
  - Gemfile
53
54
  - LICENSE.txt
54
55
  - README.md
55
56
  - Rakefile
56
57
  - app/controllers/great_pretender/mockups_controller.rb
57
58
  - app/helpers/great_pretender/mockups_helper.rb
59
+ - app/views/great_pretender/_index.html.erb
58
60
  - app/views/great_pretender/index.html.erb
59
61
  - config/locales/en.yml
60
62
  - config/routes.rb
@@ -65,7 +67,6 @@ files:
65
67
  - lib/great_pretender/engine.rb
66
68
  - lib/great_pretender/mockup.rb
67
69
  - lib/great_pretender/mockup_locator.rb
68
- - lib/great_pretender/pretender.rb
69
70
  - lib/great_pretender/version.rb
70
71
  - spec/controllers/great_pretender/mockups_controller_spec.rb
71
72
  - spec/fixtures/view_path_a/.DS_Store
@@ -80,14 +81,13 @@ files:
80
81
  - spec/lib/great_pretender/config_spec.rb
81
82
  - spec/lib/great_pretender/mockup_locator_spec.rb
82
83
  - spec/lib/great_pretender/mockup_spec.rb
83
- - spec/lib/great_pretender/pretender_spec.rb
84
84
  - spec/spec_helper.rb
85
85
  - spec/support/mockup_helpers.rb
86
86
  homepage: https://github.com/BackForty/great_pretender
87
87
  licenses:
88
88
  - MIT
89
89
  metadata: {}
90
- post_install_message:
90
+ post_install_message:
91
91
  rdoc_options: []
92
92
  require_paths:
93
93
  - lib
@@ -102,26 +102,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubyforge_project:
106
- rubygems_version: 2.2.2
107
- signing_key:
105
+ rubygems_version: 3.1.6
106
+ signing_key:
108
107
  specification_version: 4
109
108
  summary: Ridiculously easy-to-use Rails mockups for those enlightened individuals
110
109
  who design in-browser
111
- test_files:
112
- - spec/controllers/great_pretender/mockups_controller_spec.rb
113
- - spec/fixtures/view_path_a/.DS_Store
114
- - spec/fixtures/view_path_a/layouts/admin.html.slim
115
- - spec/fixtures/view_path_a/layouts/admin/base.html.slim
116
- - spec/fixtures/view_path_a/mockups/_partial.haml
117
- - spec/fixtures/view_path_a/mockups/no_processed.slim
118
- - spec/fixtures/view_path_a/mockups/processed.html.erb
119
- - spec/fixtures/view_path_b/mockups/_partial.html.haml
120
- - spec/fixtures/view_path_b/mockups/admin/base/nested_layout.html.slim
121
- - spec/fixtures/view_path_b/mockups/admin/index.html.erb
122
- - spec/lib/great_pretender/config_spec.rb
123
- - spec/lib/great_pretender/mockup_locator_spec.rb
124
- - spec/lib/great_pretender/mockup_spec.rb
125
- - spec/lib/great_pretender/pretender_spec.rb
126
- - spec/spec_helper.rb
127
- - spec/support/mockup_helpers.rb
110
+ test_files: []
@@ -1,68 +0,0 @@
1
- require "active_support/core_ext/string/inflections"
2
-
3
- module GreatPretender
4
- class Pretender
5
-
6
- def initialize(mockup)
7
- @mockup = mockup
8
- end
9
-
10
- def to_module
11
- pretenders = load_pretenders
12
-
13
- Module.new do
14
- define_method(:method_missing) do |method_name, *args, &block|
15
- pretender = pretenders.find { |p| p.respond_to?(method_name) }
16
-
17
- if pretender
18
- if defined? Rails
19
- deprecation_warning = I18n.t('great_pretender.deprecated_pretender')
20
- deprecation_warning_args = [method_name, pretender.class.name.underscore.gsub(/_pretender$/, ''), method_name]
21
- Rails.logger.debug deprecation_warning % deprecation_warning_args
22
- end
23
- pretender.send(method_name, *args, &block)
24
- else
25
- super(method_name, *args, &block)
26
- end
27
- end
28
- end
29
- end
30
-
31
- private
32
-
33
- def load_pretender(class_name)
34
- class_name = class_name + 'Pretender'
35
- begin
36
- klass = class_name.constantize
37
- rescue NameError
38
- return nil
39
- end
40
-
41
- initialize = klass.instance_method(:initialize)
42
-
43
- if initialize.arity == 1
44
- klass.new(@mockup)
45
- else
46
- klass.new
47
- end
48
- end
49
-
50
- def load_pretenders
51
- pretenders = []
52
- @mockup.slug.split("/").each do |pretender_name|
53
- # Given a mockup named something like 'social_contents',
54
- # support pretenders named 'SocialContentsPretender' AND 'SocialContentPretender'
55
- singular_class = pretender_name.classify
56
- plural_class = singular_class.pluralize
57
-
58
- [singular_class, plural_class].each do |class_name|
59
- if instance = load_pretender(class_name)
60
- pretenders.push(instance)
61
- end
62
- end
63
- end
64
- pretenders.reverse
65
- end
66
-
67
- end
68
- end
@@ -1,92 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'great_pretender/pretender'
4
- require 'i18n'
5
- require 'ostruct'
6
-
7
- module Rails
8
- def self.logger
9
- @logger ||= Class.new do
10
- def debug(msg)
11
- puts msg
12
- end
13
- end.new
14
- end
15
- end
16
-
17
- class PrefixSlugPretender
18
- def say_hello
19
- "Hello, guest!"
20
- end
21
-
22
- def name
23
- "Flip"
24
- end
25
- end
26
-
27
- class TestSlugsPretender
28
- attr_reader :mockup
29
-
30
- def initialize(mockup)
31
- @mockup = mockup
32
- end
33
-
34
- def ohai
35
- "ohai"
36
- end
37
-
38
- def name
39
- "Avery"
40
- end
41
- end
42
-
43
-
44
- I18n.load_path = Dir['config/locales/*.yml']
45
- I18n.enforce_available_locales = false
46
-
47
- describe GreatPretender::Pretender do
48
-
49
- let(:mockup) { OpenStruct.new(slug: "prefix_slug/test_slug") }
50
- let(:pretender) { GreatPretender::Pretender.new(mockup) }
51
- let(:recipient) do
52
- mod = pretender.to_module
53
- Class.new { include mod }.new
54
- end
55
-
56
- let(:deprecation_warning) { }
57
-
58
- before do |example, options|
59
- if example.metadata[:deprecations]
60
- deprecation_warning = I18n.t('great_pretender.deprecated_pretender')
61
- deprecation_warning = deprecation_warning % example.metadata[:deprecations]
62
- expect(Rails.logger).to receive(:debug).with(deprecation_warning)
63
- end
64
- end
65
-
66
- it "delegates methods to pretenders named after mockups", deprecations: %w(ohai test_slugs ohai) do
67
- expect(recipient.ohai).to eq("ohai")
68
- end
69
-
70
- it "delegates methods to pretenders in the slug chain", deprecations: %w(say_hello prefix_slug say_hello) do
71
- expect(recipient.say_hello).to eq("Hello, guest!")
72
- end
73
-
74
- it "delegates methods to the most specific responder", deprecations: %w(name test_slugs name) do
75
- expect(recipient.name).to eq("Avery")
76
- end
77
-
78
- it "passes the mockup to pretenders that accept an initialization argument" do
79
- expect(TestSlugsPretender).to receive(:new).with(mockup)
80
- recipient
81
- end
82
-
83
- it "correctly calls super when a method doesn't exist" do
84
- expect(-> { recipient.foobar }).to raise_error(NoMethodError)
85
- end
86
-
87
- it "quietly flunks mockups without pretenders" do
88
- pretenderless_mockup = OpenStruct.new(slug: "no_pretender_mockup")
89
- expect(-> { GreatPretender::Pretender.new(pretenderless_mockup) } ).not_to raise_error
90
- end
91
-
92
- end