bard-static 2.0.0

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
+ data.tar.gz: c2b95f092ff81d17479743cfdb159bab9dc390af
4
+ metadata.gz: 3ce225c3b9895daf24d05056cf6a3708a94c0b74
5
+ SHA512:
6
+ data.tar.gz: 753f53f42c11abbfcbfd67d5f9cd7d7d5e828aaf4d3ae86a33e8eb16607d7c14a39daf4530300abd7d4ead582e85334979db52066ebcbd73582f3275d463a754
7
+ metadata.gz: e819eb332ad4301e7c0dce205790c5fa72d29b5b8ff45744d0480503a0ceb80c78764c28594c96368514624de4a8d5584f86761c27f7e75fc5f42ca613cb6cc6
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails"
4
+ gem "rake"
5
+ gem "capybara"
6
+ gem "rspec-rails"
7
+
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ Forked from kiskolabs/carpentry to change paths
2
+
3
+ BardStatic
4
+ =========
5
+
6
+ _____________________________________
7
+ / BardStatic – handcrafted prototypes \
8
+ \ with ease /
9
+ -------------------------------------
10
+ \ ^__^
11
+ \ (oo)\_______
12
+ (__)\ )\/\
13
+ ||----w |
14
+ || ||
15
+
16
+
17
+ Installation
18
+ ------------
19
+
20
+ Add BardStatic to Gemfile:
21
+
22
+ gem "bard_static"
23
+
24
+ Usage
25
+ -----
26
+
27
+ Put your views in app/views/mockups and view them in
28
+ browser at /mockups/path_to_file.
29
+
30
+ Examples:
31
+
32
+ | URI Path | File path |
33
+ |--------------------|---------------------------------------|
34
+ | /mockups | app/views/mockups/index.html.erb |
35
+ | /mockups/home | app/views/mockups/home.html.haml |
36
+ | /mockups/posts/new | app/views/mockups/posts/new.html.slim |
37
+
38
+ All available Rails helpers work nicely. Pure prototyping bliss!
39
+
40
+
41
+ Hooks
42
+ -----
43
+
44
+ BardStatic let's you add a `#before_bard_static` method in
45
+ `ApplicationController`, that will be run before any prototype. You can
46
+ use it, for example, to provide authentication or prevent prototypes
47
+ from being rendered in production.
48
+
49
+
50
+ Gotchas
51
+ -------
52
+
53
+ When rendering a partial, you must specify the full path
54
+ (e.g. `mockups/posts/form`) unless the partial is in
55
+ `app/views/mockups/`.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+
5
+ require 'rake'
6
+ require 'rake/task'
7
+
8
+ require 'rspec/core'
9
+ require 'rspec/core/rake_task'
10
+
11
+ RSpec::Core::RakeTask.new(:spec)
12
+ Bundler::GemHelper.install_tasks
13
+
14
+ task :default => :spec
@@ -0,0 +1,40 @@
1
+ module Bard
2
+ module Static
3
+ class StaticController < ApplicationController
4
+ before_filter :before_bard_static,
5
+ :if => proc { respond_to?(:before_bard_static, true) }
6
+
7
+ def mockups
8
+ env["bard_static.prototype"] = true
9
+ with_404_handler { render_with_index "mockups/#{params[:file_path]}", :layout => false }
10
+ end
11
+
12
+ def static
13
+ layout = !request.xhr? # render ajax responses with no layout
14
+ with_404_handler { render_with_index "static/#{params[:file_path]}", :layout => layout }
15
+ end
16
+
17
+ private
18
+
19
+ def with_404_handler
20
+ begin
21
+ yield
22
+ rescue ActionView::MissingTemplate
23
+ render :text => "Not Found", :status => 404
24
+ end
25
+ end
26
+
27
+ def render_with_index path, options = {}
28
+ begin
29
+ options = options.dup # render is destructive to the options hash!
30
+ options = options.merge(:template => path)
31
+ render options
32
+ rescue ActionView::MissingTemplate
33
+ options[:template] = "#{path}/index"
34
+ render options
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,9 @@
1
+ module Bard
2
+ module Static
3
+ module LayoutHelper
4
+ def layout layout, &block
5
+ render :text => capture(&block), :layout => "layouts/#{layout}"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,93 @@
1
+ module Bard
2
+ module Static
3
+ module LinkToHelper
4
+ def link_to(*args, &block)
5
+ args.unshift capture(&block) if block_given?
6
+ LinkTo.render(self, *args)
7
+ end
8
+
9
+ def link_to_current(*args, &block)
10
+ args.unshift capture(&block) if block_given?
11
+ LinkToCurrent.render(self, *args) do |link|
12
+ link.current_path = request.fullpath
13
+ end
14
+ end
15
+
16
+ def link_to_nav(*args, &block)
17
+ args.unshift capture(&block) if block_given?
18
+ LinkToNav.render(self, *args) do |link|
19
+ link.current_path = request.fullpath
20
+ end
21
+ end
22
+
23
+ class LinkTo
24
+ def self.render *args, &block
25
+ if block_given?
26
+ new(*args, &block).render
27
+ else
28
+ new(*args).render
29
+ end
30
+ end
31
+
32
+ def initialize context, name, options = {}, html_options = {}, &block
33
+ @context = context
34
+ @name = name
35
+ @options = options || {}
36
+ @html_options = HashWithIndifferentAccess.new(html_options)
37
+ @html_options = @context.send(:convert_options_to_data_attributes, @options, @html_options)
38
+ yield self if block_given?
39
+ end
40
+
41
+ def render
42
+ "<a #{href_attr}#{tag_options}>#{body}</a>".html_safe
43
+ end
44
+
45
+ attr_reader :context, :name, :options, :html_options
46
+
47
+ def url
48
+ context.url_for(options)
49
+ end
50
+
51
+ private
52
+
53
+ def href_attr
54
+ "href=\"#{ERB::Util.html_escape(url)}\"" unless html_options["href"]
55
+ end
56
+
57
+ def tag_options
58
+ context.send(:tag_options, html_options)
59
+ end
60
+
61
+ def body
62
+ ERB::Util.html_escape(name || url)
63
+ end
64
+ end
65
+
66
+ class LinkToCurrent < LinkTo
67
+ attr_accessor :current_path
68
+
69
+ def add_class class_name
70
+ html_options[:class] ||= ""
71
+ html_options[:class] << " #{class_name}"
72
+ html_options[:class].strip!
73
+ end
74
+
75
+ def render
76
+ add_class("current") if current_condition
77
+ super
78
+ end
79
+
80
+ def current_condition
81
+ html_options.delete(:if) || current_path == url
82
+ end
83
+ end
84
+
85
+ class LinkToNav < LinkToCurrent
86
+ def current_condition
87
+ super || current_path.starts_with?(url)
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
@@ -0,0 +1 @@
1
+ <% exit %>
data/config/routes.rb ADDED
@@ -0,0 +1,8 @@
1
+ Rails.application.routes.draw do
2
+ namespace "mockups", :module => "bard/static" do
3
+ root :to => "static#mockups", :file_path => "index"
4
+ get "/*file_path" => "static#mockups"
5
+ end
6
+ root :to => "bard/static/static#static", :file_path => "index", :as => "bard_static_default_root"
7
+ get "*file_path" => "bard/static/static#static"
8
+ end
@@ -0,0 +1 @@
1
+ require "bard/static"
@@ -0,0 +1,9 @@
1
+ require "bard/static/no_robots_middleware"
2
+
3
+ module Bard
4
+ module Static
5
+ class Engine < ::Rails::Engine
6
+ config.app_middleware.use NoRobotsMiddleware
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ module Bard
2
+ module Static
3
+ class NoRobotsMiddleware
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ status, headers, response = @app.call(env)
10
+
11
+ if env["bard_static.prototype"] && status == 200
12
+ no_robots_tag = %{<meta name="robots" content="noindex, nofollow"/>\n}
13
+ response.each do |part|
14
+ part.sub! "</head>", "#{no_robots_tag}</head>"
15
+ end
16
+ end
17
+
18
+ [status, headers, response]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ module Bard
2
+ module Static
3
+ VERSION = "2.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bard-static
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Micah Geisel
8
+ - Joao Carlos
9
+ - !binary |
10
+ VmVzYSBWw6Ruc2vDpA==
11
+
12
+ - Matias Korhonen
13
+ - Antti Salonen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-12-12 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Handcrafted prototypes for Rails.
22
+ email:
23
+ - micah@botandrose.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - app/controllers/bard/static/static_controller.rb
32
+ - app/views/bard/static/error.html.erb
33
+ - app/helpers/bard/static/link_to_helper.rb
34
+ - app/helpers/bard/static/layout_helper.rb
35
+ - lib/bard-static.rb
36
+ - lib/bard/static.rb
37
+ - lib/bard/static/version.rb
38
+ - lib/bard/static/no_robots_middleware.rb
39
+ - config/routes.rb
40
+ - Rakefile
41
+ - Gemfile
42
+ - README.md
43
+ homepage: https://github.com/botandrose/bard-static
44
+ licenses: []
45
+
46
+ metadata: {}
47
+
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - &id001
56
+ - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - *id001
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 2.1.10
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Protoyping engine for Rails.
69
+ test_files: []
70
+