great_pretender 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d7bef2a3f4eedc66d221d827f8a6f747cb54b4c
4
+ data.tar.gz: 4e36bcc3085b77217e178240f1e6aa22098dfc52
5
+ SHA512:
6
+ metadata.gz: a2a4192ad7d8997fb34aad458289b6a189ca99b3d31b8f1f21bf8e6fd2fab7bf027b965192a275b335adf6faa179ded3016de479e53bd1447314e62332b88444
7
+ data.tar.gz: f9f15adcb02f5466ee6447267e2c00374bf2a839943a90726e6677ea4cfd17f8ffe2ab630e742f1a2bc2e9ae020c19071d234732981a6acbcf2374c7c8eb278d
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in great_pretender.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Flip Sasser
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.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # GreatPretender
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'great_pretender'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install great_pretender
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/great_pretender/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,9 @@
1
+ require 'great_pretender/controller'
2
+
3
+ module GreatPretender
4
+ class MockupsController < ::ApplicationController
5
+
6
+ include GreatPretender::Controller
7
+
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ module GreatPretender
2
+ module MockupsHelper
3
+
4
+ def great_pretender_mockup_path(mockup)
5
+ if controller.is_a?(GreatPretender::MockupsController)
6
+ great_pretender_engine.mockup_path(mockup)
7
+ else
8
+ path_helper = controller_path.split("/")
9
+ path_helper = path_helper.join("_")
10
+ path_helper = path_helper.singularize
11
+ path_helper << '_url'
12
+ begin
13
+ send(path_helper, mockup)
14
+ rescue NoMethodError => error
15
+ 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)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ class MissingPathHelperError < StandardError
24
+ def initialize(message, error)
25
+ super(message)
26
+ @original_error = error
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,30 @@
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
+
@@ -0,0 +1,4 @@
1
+ en:
2
+ great_pretender:
3
+ missing_helper_methods: "Great Pretender couldn't find a path helper to a mockup from %s. I tried '%s' to no avail. Have you named your mockup routes?"
4
+ not_found: "No mockup found at %s"
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ 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
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'great_pretender/version'
5
+
6
+ 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"
15
+
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)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,21 @@
1
+ module GreatPretender
2
+
3
+ class Config
4
+ attr_accessor :default_layout, :path_separator, :view_path
5
+ end
6
+
7
+ def self.config
8
+ @config ||= Config.new
9
+ if block_given?
10
+ yield @config
11
+ end
12
+ @config
13
+ end
14
+
15
+ end
16
+
17
+ GreatPretender.config do |c|
18
+ c.default_layout = 'application'
19
+ c.path_separator = ' > '
20
+ c.view_path = 'mockups'
21
+ end
@@ -0,0 +1,45 @@
1
+ require "great_pretender/mockup_locator"
2
+
3
+ module GreatPretender
4
+ module Controller
5
+
6
+ def self.included(base)
7
+ base.helper_method :mockup
8
+ base.helper_method :mockups
9
+ base.helper_method :mockup_root
10
+ base.helper GreatPretender::MockupsHelper
11
+ end
12
+
13
+ def index
14
+ render template: 'great_pretender/index'
15
+ end
16
+
17
+ def show
18
+ if mockup
19
+ render template: mockup.template, layout: mockup.layout
20
+ else
21
+ error_message = I18n.t('great_pretender.not_found') % params[:id]
22
+ raise ActiveRecord::RecordNotFound.new(error_message)
23
+ end
24
+ end
25
+
26
+ private
27
+
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
34
+ end
35
+
36
+ def mockup_locator
37
+ @great_pretender_mockup_locator ||= MockupLocator.new(view_paths)
38
+ end
39
+
40
+ def mockup_root
41
+ @great_pretender_mockup_root ||= mockup_locator.view_paths.first.join(GreatPretender.config.view_path)
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,4 @@
1
+ module GreatPretender
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,29 @@
1
+ require "active_support/core_ext/string/inflections"
2
+ require "great_pretender/config"
3
+
4
+ module GreatPretender
5
+ class Mockup
6
+
7
+ attr_accessor :layout, :slug, :template
8
+
9
+ alias :to_param :slug
10
+
11
+ def initialize(path)
12
+ @file = Pathname.new(path)
13
+ end
14
+
15
+ def name
16
+ return @name if defined? @name
17
+ name = slug.split('/').map { |s| s.titleize }.join(GreatPretender.config.path_separator)
18
+ if slug =~ /^_/
19
+ name << ' (partial)'
20
+ end
21
+ @name = name
22
+ end
23
+
24
+ def updated_at
25
+ @file.mtime
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,87 @@
1
+ require "great_pretender/config"
2
+ require "great_pretender/mockup"
3
+
4
+ module GreatPretender
5
+ class MockupLocator
6
+
7
+ attr_reader :view_paths
8
+
9
+ def find(slug)
10
+ mockups.find {|mockup| mockup.slug == slug}
11
+ end
12
+
13
+ def mockups
14
+ return @mockups if defined? @mockups
15
+ mockups = []
16
+ @view_paths.each do |view_path|
17
+ root = view_path.join(GreatPretender.config.view_path)
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
26
+ end
27
+ @mockups = mockups
28
+ end
29
+
30
+ def initialize(view_paths)
31
+ @view_paths = view_paths.map do |view_path|
32
+ if view_path.is_a?(Pathname)
33
+ view_path
34
+ elsif view_path.respond_to?(:to_path)
35
+ Pathname.new(view_path.to_path)
36
+ else
37
+ Pathname.new(view_path.to_s)
38
+ end
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def extensions
45
+ return @extensions if defined? @extensions
46
+ extensions = ActionView::Template.template_handler_extensions
47
+ extensions = extensions.map(&:to_s).join(',')
48
+ @extensions = "{#{extensions}}"
49
+ end
50
+
51
+ def layout_for(slug)
52
+ if File.basename(slug) =~ /^_/
53
+ # Partials (named like "_template_name") don't render inside a layout.
54
+ # This way they can be used w/Ajax requests, etc.
55
+ nil
56
+ else
57
+ # Mockups can have a layout by being in a folder named after that
58
+ # layout; for example, "app/views/mockups/admin/index" will look for an
59
+ # "admin" template
60
+ layout = slug.split('/').first
61
+ if layout && layout.length > 0
62
+ @view_paths.each do |view_path|
63
+ layout_path = view_path.join('layouts')
64
+ layout_path = layout_path.join("#{layout}.*#{extensions}")
65
+ puts "\n\n\n" + layout_path.inspect + "\n\n\n"
66
+ return layout if Dir[layout_path].any?
67
+ end
68
+ end
69
+ GreatPretender.config.default_layout
70
+ end
71
+ end
72
+
73
+ def slug_for(root, path)
74
+ slug = path.to_s.gsub(%r{^#{root.to_s}/}, '')
75
+ while (ext = File.extname(slug)).length > 0
76
+ slug = slug.gsub(/#{ext}$/, '')
77
+ end
78
+ slug
79
+ end
80
+
81
+ def template_for(view_path, root, slug)
82
+ template_root = root.relative_path_from(view_path)
83
+ template_root.join(slug).to_s
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module GreatPretender
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "great_pretender/config"
2
+ require "great_pretender/controller"
3
+ require "great_pretender/version"
4
+
5
+ module GreatPretender
6
+ end
7
+
8
+ require "great_pretender/engine" if defined? Rails
Binary file
File without changes
File without changes
@@ -0,0 +1,37 @@
1
+ module GreatPretender; end
2
+
3
+ describe GreatPretender do
4
+
5
+ context ".config" do
6
+
7
+ before { load("great_pretender/config.rb") }
8
+
9
+ context "default configuration values" do
10
+
11
+ it "has 'application' as the default layout" do
12
+ expect(GreatPretender.config.default_layout).to eq("application")
13
+ end
14
+
15
+ it "has 'mockups' as the default view path" do
16
+ expect(GreatPretender.config.view_path).to eq("mockups")
17
+ end
18
+
19
+ end
20
+
21
+ it "accepts a block" do
22
+ GreatPretender.config do |c|
23
+ c.default_layout = "another_layout"
24
+ c.view_path = "somewhere"
25
+ end
26
+ expect(GreatPretender.config.default_layout).to eq("another_layout")
27
+ expect(GreatPretender.config.view_path).to eq("somewhere")
28
+ end
29
+
30
+ it "can be used for direct setting of configuration options" do
31
+ GreatPretender.config.default_layout = "a_third_layout"
32
+ expect(GreatPretender.config.default_layout).to eq("a_third_layout")
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,52 @@
1
+ require 'great_pretender/mockup_locator'
2
+ require 'pathname'
3
+ require_relative '../../support/mockup_helpers'
4
+
5
+ module ActionView
6
+ module Template
7
+ def self.template_handler_extensions
8
+ %w(erb slim haml)
9
+ end
10
+ end
11
+ end
12
+
13
+ describe GreatPretender::MockupLocator do
14
+
15
+ include MockupHelpers
16
+
17
+ let(:regular_mockup) { mockup_locator.mockups.find {|m| m.slug =~ /^processed/ } }
18
+ let(:partial_mockup) { mockup_locator.mockups.find {|m| m.slug =~ /^_/ } }
19
+ let(:admin_mockup) { mockup_locator.mockups.find {|m| m.slug =~ /admin/ } }
20
+
21
+ context "::mockups" do
22
+ it "returns all mockups in the pre-configured mockup directories" do
23
+ expect(mockup_locator.mockups.size).to eq(5)
24
+ end
25
+
26
+ it "returns mockups with Rails-friendly template names" do
27
+ expect(regular_mockup.template).to eq("mockups/processed")
28
+ end
29
+
30
+ it "returns mockups with the default layout if they have no discernible alternative" do
31
+ expect(regular_mockup.layout).to eq(GreatPretender.config.default_layout)
32
+ end
33
+
34
+ it "returns partials with no layout" do
35
+ expect(partial_mockup.layout).to be_nil
36
+ end
37
+
38
+ it "returns detected layouts for well-named mockups" do
39
+ expect(admin_mockup.layout).to eq("admin")
40
+ end
41
+ end
42
+
43
+ context "::find" do
44
+ it "returns mockups given a slug" do
45
+ expect(mockup_locator.find("processed")).to eq(regular_mockup)
46
+ end
47
+
48
+ it "returns nil given a bad mockup name" do
49
+ expect(mockup_locator.find("foobar")).to be_nil
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,26 @@
1
+ require 'great_pretender/mockup'
2
+ require_relative '../../support/mockup_helpers'
3
+
4
+ describe GreatPretender::Mockup do
5
+
6
+ include MockupHelpers
7
+
8
+ let(:mockup) { mockup_locator.mockups.find {|m| m.slug =~ /admin/ } }
9
+
10
+ it "returns a human-readable name from its slug" do
11
+ expect(mockup.name).to eq("Admin > Index")
12
+ end
13
+
14
+ context ".to_param" do
15
+ it "returns the slug" do
16
+ expect(mockup.to_param).to eq(mockup.slug)
17
+ end
18
+ end
19
+
20
+ context ".updated_at" do
21
+ it "returns the template file's mtime for its slug" do
22
+ expect(mockup.updated_at).to eq(Time.at(1407427839))
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,26 @@
1
+ module MockupHelpers
2
+ def self.included(base)
3
+ base.class_eval do
4
+
5
+ let(:paths) do
6
+ [
7
+ Pathname.new("spec/fixtures/view_path_a").expand_path,
8
+ Stub.new("spec/fixtures/view_path_b")
9
+ ]
10
+ end
11
+
12
+ let(:mockup_locator) { GreatPretender::MockupLocator.new(paths) }
13
+
14
+ end
15
+ 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
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: great_pretender
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Flip Sasser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Use Great Pretender to easily add layout-specific mockups in a Rails
42
+ app without having to recreate the mockup wheel. Your design should be happening
43
+ in-browser; this will help you get there.
44
+ email:
45
+ - flip@inthebackforty.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - ".rspec"
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - app/controllers/great_pretender/mockups_controller.rb
57
+ - app/helpers/great_pretender/mockups_helper.rb
58
+ - app/views/great_pretender/index.html.erb
59
+ - config/locales/en.yml
60
+ - config/routes.rb
61
+ - great_pretender.gemspec
62
+ - lib/great_pretender.rb
63
+ - lib/great_pretender/config.rb
64
+ - lib/great_pretender/controller.rb
65
+ - lib/great_pretender/engine.rb
66
+ - lib/great_pretender/mockup.rb
67
+ - lib/great_pretender/mockup_locator.rb
68
+ - lib/great_pretender/version.rb
69
+ - spec/fixtures/view_path_a/.DS_Store
70
+ - spec/fixtures/view_path_a/layouts/admin.html.slim
71
+ - spec/fixtures/view_path_a/mockups/_partial.haml
72
+ - spec/fixtures/view_path_a/mockups/no_processed.slim
73
+ - spec/fixtures/view_path_a/mockups/processed.html.erb
74
+ - spec/fixtures/view_path_b/mockups/_partial.html.haml
75
+ - spec/fixtures/view_path_b/mockups/admin/index.html.erb
76
+ - spec/lib/great_pretender/config_spec.rb
77
+ - spec/lib/great_pretender/mockup_locator_spec.rb
78
+ - spec/lib/great_pretender/mockup_spec.rb
79
+ - spec/support/mockup_helpers.rb
80
+ homepage: https://github.com/BackForty/great_pretender
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.1
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Ridiculously easy-to-use Rails mockups for those enlightened individuals
104
+ who design in-browser
105
+ test_files:
106
+ - spec/fixtures/view_path_a/.DS_Store
107
+ - spec/fixtures/view_path_a/layouts/admin.html.slim
108
+ - spec/fixtures/view_path_a/mockups/_partial.haml
109
+ - spec/fixtures/view_path_a/mockups/no_processed.slim
110
+ - spec/fixtures/view_path_a/mockups/processed.html.erb
111
+ - spec/fixtures/view_path_b/mockups/_partial.html.haml
112
+ - spec/fixtures/view_path_b/mockups/admin/index.html.erb
113
+ - spec/lib/great_pretender/config_spec.rb
114
+ - spec/lib/great_pretender/mockup_locator_spec.rb
115
+ - spec/lib/great_pretender/mockup_spec.rb
116
+ - spec/support/mockup_helpers.rb