myth-rails 1.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: bc65fc0841316f8dff4e0518b1d63e6ee88f4366
4
+ data.tar.gz: 2f69823f55ab807aa38bb91c70fdaaa2f1de22a2
5
+ SHA512:
6
+ metadata.gz: 5d7906c070ee9c94e1aeef92f2753846f2a9119b497564d8bb8e756f5efd160ae1d1d2155d744133808e2f7e22493e8629a0aff039606569e799c44a0ab16811
7
+ data.tar.gz: 3d97cbb22b835bcdd00be9bed429634ff6704330715e6076993f3cdb0df61b93a7bd42f710bc9aa0f7a5770b5f7cd061b6b2e838af03541aa259e2c536d4d1da
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2014 Dan Schultzer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Myth-Rails
2
+
3
+ Myth adapter for the Rails asset pipeline.
4
+
5
+ ## Installation
6
+
7
+ gem install myth-rails
8
+
9
+ If you are precompiling your assets (with rake assets:precompile) before run your application in production, you might want add it to the assets group to prevent the gem being required in the production environment.
10
+
11
+ group :assets do
12
+ gem 'myth-rails'
13
+ end
14
+
15
+ ## Usage
16
+
17
+ Stylesheet files depending on Myth should contain a `.myth` extension.
18
+
19
+ ## Running tests
20
+
21
+ $ bundle install
22
+ $ bundle exec rake test
23
+
24
+ If you need to test against local gems, use Bundler's gem :path option in the Gemfile.
25
+
26
+ ## Code Status
27
+
28
+ * [![Travis CI](https://api.travis-ci.org/dreamconception/myth-rails.png)](http://travis-ci.org/rails/myth-rails)
29
+ * [![Gem Version](https://badge.fury.io/rb/myth-rails.png)](http://badge.fury.io/rb/myth-rails)
30
+ * [![Dependencies](https://gemnasium.com/dreamconception/myth-rails.png)](https://gemnasium.com/rails/myth-rails)
@@ -0,0 +1 @@
1
+ <%= Myth::Source.contents %>
@@ -0,0 +1,12 @@
1
+ require 'tilt'
2
+ require 'rails/engine'
3
+
4
+ module Myth
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ initializer 'myth-rails.sprockets_engine', after: 'sprockets.environment', group: :all do |app|
8
+ app.assets.register_engine '.myth', MythTemplate
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ require 'tilt'
2
+ require 'myth'
3
+
4
+ module Myth
5
+ module Rails
6
+ # Myth template implementation. See:
7
+ # http://myth.io/
8
+ #
9
+ # Myth templates do not support object scopes, locals, or yield.
10
+ class MythTemplate < ::Tilt::Template
11
+ self.default_mime_type = 'text/css'
12
+
13
+ def prepare
14
+ end
15
+
16
+ def evaluate(scope, locals, &block)
17
+ @output ||= ::Myth.preprocess(data, options)
18
+ end
19
+
20
+ def allows_script?
21
+ false
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ module Myth
2
+ module Rails
3
+ class TemplateHandler
4
+ def self.erb_handler
5
+ @@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
6
+ end
7
+
8
+ def self.call(template)
9
+ compiled_source = erb_handler.call(template)
10
+ "Myth.preprocess(begin;#{compiled_source};end)"
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ ActiveSupport.on_load(:action_view) do
17
+ ActionView::Template.register_template_handler :myth, Myth::Rails::TemplateHandler
18
+ end
@@ -0,0 +1,5 @@
1
+ module Myth
2
+ module Rails
3
+ VERSION = "1.0.1"
4
+ end
5
+ end
data/lib/myth-rails.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'myth'
2
+ require 'myth/rails/template_handler'
3
+ require 'myth/rails/myth_template'
4
+ require 'myth/rails/engine'
5
+ require 'myth/rails/version'
@@ -0,0 +1,13 @@
1
+ require "rails/generators/named_base"
2
+
3
+ module Myth
4
+ module Generators
5
+ class AssetsGenerator < ::Rails::Generators::NamedBase
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ def copy_myth
9
+ template "stylesheet.css.myth", File.join('app/assets/stylesheets', class_path, "#{file_name}.css.myth")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ # Don't worry about slow browser support or slow spec approval,
2
+ # Myth can preprocess this file: http://www.myth.io/
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+ require 'rails/generators/myth/assets/assets_generator'
3
+
4
+ class AssetGeneratorTest < Rails::Generators::TestCase
5
+ tests Myth::Generators::AssetsGenerator
6
+
7
+ destination File.expand_path("../tmp", __FILE__)
8
+ setup :prepare_destination
9
+
10
+ def test_assets
11
+ run_generator %w(posts)
12
+ assert_no_file "app/assets/stylesheets/posts.css"
13
+ assert_file "app/assets/stylesheets/posts.css.myth"
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+ require 'myth-rails'
3
+
4
+ class AssetsTest < ActiveSupport::TestCase
5
+ def setup
6
+ require "rails"
7
+ require "action_controller/railtie"
8
+ require "sprockets/railtie"
9
+
10
+ @app = Class.new(Rails::Application)
11
+ @app.config.eager_load = false
12
+ @app.config.active_support.deprecation = :stderr
13
+ @app.config.assets.enabled = true
14
+ @app.config.assets.cache_store = [ :file_store, "#{tmp_path}/cache" ]
15
+ @app.paths["log"] = "#{tmp_path}/log/test.log"
16
+ @app.initialize!
17
+ end
18
+
19
+ def teardown
20
+ FileUtils.rm_rf "#{tmp_path}/cache"
21
+ FileUtils.rm_rf "#{tmp_path}/log"
22
+ File.delete "#{tmp_path}/myth.js"
23
+ end
24
+
25
+ test "myth.js is included in Sprockets environment" do
26
+ @app.assets["myth"].write_to("#{tmp_path}/myth.js")
27
+
28
+ assert_match "/lib/assets/stylesheets/myth.css.erb", @app.assets["myth"].pathname.to_s
29
+ assert_match "function myth", File.open("#{tmp_path}/myth.js").read
30
+ end
31
+
32
+ def tmp_path
33
+ "#{File.dirname(__FILE__)}/tmp"
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+ require 'rails/generators/rails/controller/controller_generator'
3
+ require 'rails/generators/myth/assets/assets_generator'
4
+
5
+ class ControllerGeneratorTest < Rails::Generators::TestCase
6
+ tests Rails::Generators::ControllerGenerator
7
+
8
+ destination File.expand_path("../tmp", __FILE__)
9
+ setup do
10
+ prepare_destination
11
+ copy_routes
12
+ end
13
+
14
+ def test_assets
15
+ run_generator %w(posts --stylesheet-engine=myth --orm=false)
16
+ assert_no_file "app/assets/stylesheets/posts.css"
17
+ assert_file "app/assets/stylesheets/posts.css.myth"
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+ require 'rails/generators/rails/scaffold/scaffold_generator'
3
+ require 'rails/generators/myth/assets/assets_generator'
4
+
5
+ class ScaffoldGeneratorTest < Rails::Generators::TestCase
6
+ tests Rails::Generators::ScaffoldGenerator
7
+
8
+ destination File.expand_path("../tmp", __FILE__)
9
+ setup do
10
+ prepare_destination
11
+ copy_routes
12
+ end
13
+
14
+ def test_assets
15
+ run_generator %w(posts --stylesheet-engine=myth --orm=false)
16
+ assert_no_file "app/assets/stylesheets/posts.css"
17
+ assert_file "app/assets/stylesheets/posts.css.myth"
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ # routes dummy file
@@ -0,0 +1,51 @@
1
+ a {
2
+ color: #a6c776;
3
+ -webkit-font-feature-settings: "smcp", "c2sc";
4
+ -moz-font-feature-settings: "smcp", "c2sc";
5
+ font-feature-settings: "smcp", "c2sc";
6
+ font-variant: all-small-caps;
7
+ -webkit-transition: color 1s;
8
+ transition: color 1s;
9
+ }
10
+
11
+ a:hover {
12
+ color: rgb(133, 159, 94);
13
+ }
14
+
15
+ ::-webkit-input-placeholder {
16
+ opacity: .4;
17
+ -webkit-transition: opacity 1s;
18
+ transition: opacity 1s;
19
+ }
20
+
21
+ ::-moz-placeholder {
22
+ opacity: .4;
23
+ transition: opacity 1s;
24
+ }
25
+
26
+ :-ms-input-placeholder {
27
+ opacity: .4;
28
+ transition: opacity 1s;
29
+ }
30
+
31
+ ::placeholder {
32
+ opacity: .4;
33
+ -webkit-transition: opacity 1s;
34
+ transition: opacity 1s;
35
+ }
36
+
37
+ :focus::-webkit-input-placeholder {
38
+ opacity: .2;
39
+ }
40
+
41
+ :focus::-moz-placeholder {
42
+ opacity: .2;
43
+ }
44
+
45
+ :focus:-ms-input-placeholder {
46
+ opacity: .2;
47
+ }
48
+
49
+ :focus::placeholder {
50
+ opacity: .2;
51
+ }
@@ -0,0 +1,22 @@
1
+ :root {
2
+ var-green: #a6c776;
3
+ }
4
+
5
+ a {
6
+ color: var(green);
7
+ font-variant: all-small-caps;
8
+ transition: color 1s;
9
+ }
10
+
11
+ a:hover {
12
+ color: color(var(green) shade(20%));
13
+ }
14
+
15
+ ::placeholder {
16
+ opacity: .4;
17
+ transition: opacity 1s;
18
+ }
19
+
20
+ :focus::placeholder {
21
+ opacity: .2;
22
+ }
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+ require 'action_controller'
3
+ require 'myth-rails'
4
+
5
+ class SiteController < ActionController::Base
6
+ self.view_paths = File.expand_path("../support", __FILE__)
7
+ end
8
+
9
+ DummyApp = ActionDispatch::Routing::RouteSet.new
10
+ DummyApp.draw do
11
+ get "site/index"
12
+ end
13
+
14
+ class TemplateHandlerTest < ActiveSupport::TestCase
15
+ include Rack::Test::Methods
16
+
17
+ def app
18
+ @app ||= DummyApp
19
+ end
20
+
21
+ test "myth views are served as css" do
22
+ get "/site/index.css"
23
+
24
+ assert_match File.read(File.expand_path("../support", __FILE__) + "/site/expected.css"), last_response.body
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require 'bundler/setup'
5
+ require 'rails'
6
+ require "rails/test_help"
7
+
8
+ # For generators
9
+ require 'rails/generators/test_case'
10
+
11
+ def copy_routes
12
+ routes = File.expand_path("../support/routes.rb", __FILE__)
13
+ destination = File.join(destination_root, "config")
14
+
15
+ FileUtils.mkdir_p(destination)
16
+ FileUtils.cp routes, destination
17
+ end
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ # Don't worry about slow browser support or slow spec approval,
2
+ # Myth can preprocess this file: http://www.myth.io/
@@ -0,0 +1,58 @@
1
+ class PostsController < ApplicationController
2
+ before_action :set_post, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /posts
5
+ def index
6
+ @posts = Post.all
7
+ end
8
+
9
+ # GET /posts/1
10
+ def show
11
+ end
12
+
13
+ # GET /posts/new
14
+ def new
15
+ @post = Post.new
16
+ end
17
+
18
+ # GET /posts/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /posts
23
+ def create
24
+ @post = Post.new(post_params)
25
+
26
+ if @post.save
27
+ redirect_to @post, notice: 'Post was successfully created.'
28
+ else
29
+ render action: 'new'
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /posts/1
34
+ def update
35
+ if @post.update(post_params)
36
+ redirect_to @post, notice: 'Post was successfully updated.'
37
+ else
38
+ render action: 'edit'
39
+ end
40
+ end
41
+
42
+ # DELETE /posts/1
43
+ def destroy
44
+ @post.destroy
45
+ redirect_to posts_url, notice: 'Post was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_post
51
+ @post = Post.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def post_params
56
+ params[:post]
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ module PostsHelper
2
+ end
@@ -0,0 +1,17 @@
1
+ <%= form_for(@post) do |f| %>
2
+ <% if @post.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @post.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="actions">
15
+ <%= f.submit %>
16
+ </div>
17
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing post</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @post %> |
6
+ <%= link_to 'Back', posts_path %>
@@ -0,0 +1,23 @@
1
+ <h1>Listing posts</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th colspan="3"></th>
7
+ </tr>
8
+ </thead>
9
+
10
+ <tbody>
11
+ <% @posts.each do |post| %>
12
+ <tr>
13
+ <td><%= link_to 'Show', post %></td>
14
+ <td><%= link_to 'Edit', edit_post_path(post) %></td>
15
+ <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
16
+ </tr>
17
+ <% end %>
18
+ </tbody>
19
+ </table>
20
+
21
+ <br>
22
+
23
+ <%= link_to 'New Post', new_post_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New post</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', posts_path %>
@@ -0,0 +1,4 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <%= link_to 'Edit', edit_post_path(@post) %> |
4
+ <%= link_to 'Back', posts_path %>
@@ -0,0 +1 @@
1
+ # routes dummy file
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: myth-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dan Schultzer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: myth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ - - <
35
+ - !ruby/object:Gem::Version
36
+ version: '5.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 4.0.0
44
+ - - <
45
+ - !ruby/object:Gem::Version
46
+ version: '5.0'
47
+ description: Myth adapter for the Rails asset pipeline.
48
+ email:
49
+ - dan@dreamconception.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - MIT-LICENSE
55
+ - README.md
56
+ - lib/assets/stylesheets/myth.css.erb
57
+ - lib/myth-rails.rb
58
+ - lib/myth/rails/engine.rb
59
+ - lib/myth/rails/myth_template.rb
60
+ - lib/myth/rails/template_handler.rb
61
+ - lib/myth/rails/version.rb
62
+ - lib/rails/generators/myth/assets/assets_generator.rb
63
+ - lib/rails/generators/myth/assets/templates/stylesheet.css.myth
64
+ - test/assets_generator_test.rb
65
+ - test/assets_test.rb
66
+ - test/controller_generator_test.rb
67
+ - test/scaffold_generator_test.rb
68
+ - test/support/routes.rb
69
+ - test/support/site/expected.css
70
+ - test/support/site/index.css.myth
71
+ - test/template_handler_test.rb
72
+ - test/test_helper.rb
73
+ - test/tmp/app/assets/javascripts/posts.js
74
+ - test/tmp/app/assets/stylesheets/posts.css.myth
75
+ - test/tmp/app/controllers/posts_controller.rb
76
+ - test/tmp/app/helpers/posts_helper.rb
77
+ - test/tmp/app/views/posts/_form.html.erb
78
+ - test/tmp/app/views/posts/edit.html.erb
79
+ - test/tmp/app/views/posts/index.html.erb
80
+ - test/tmp/app/views/posts/new.html.erb
81
+ - test/tmp/app/views/posts/show.html.erb
82
+ - test/tmp/config/routes.rb
83
+ homepage: https://github.com/dreamconception/myth-rails
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.2.2
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Myth adapter for the Rails asset pipeline.
107
+ test_files:
108
+ - test/assets_generator_test.rb
109
+ - test/assets_test.rb
110
+ - test/controller_generator_test.rb
111
+ - test/scaffold_generator_test.rb
112
+ - test/support/routes.rb
113
+ - test/support/site/expected.css
114
+ - test/support/site/index.css.myth
115
+ - test/template_handler_test.rb
116
+ - test/test_helper.rb
117
+ - test/tmp/app/assets/javascripts/posts.js
118
+ - test/tmp/app/assets/stylesheets/posts.css.myth
119
+ - test/tmp/app/controllers/posts_controller.rb
120
+ - test/tmp/app/helpers/posts_helper.rb
121
+ - test/tmp/app/views/posts/_form.html.erb
122
+ - test/tmp/app/views/posts/edit.html.erb
123
+ - test/tmp/app/views/posts/index.html.erb
124
+ - test/tmp/app/views/posts/new.html.erb
125
+ - test/tmp/app/views/posts/show.html.erb
126
+ - test/tmp/config/routes.rb