mab-cj 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +19 -0
  3. data/Gemfile +14 -0
  4. data/README.md +224 -0
  5. data/Rakefile +16 -0
  6. data/lib/mab.rb +6 -0
  7. data/lib/mab/builder.rb +45 -0
  8. data/lib/mab/indentation.rb +33 -0
  9. data/lib/mab/kernel_method.rb +6 -0
  10. data/lib/mab/mixin.rb +262 -0
  11. data/lib/mab/rails.rb +20 -0
  12. data/lib/mab/tilt.rb +42 -0
  13. data/lib/mab/version.rb +4 -0
  14. data/mab.gemspec +20 -0
  15. data/test/helper.rb +4 -0
  16. data/test/rails/Rakefile +7 -0
  17. data/test/rails/app/assets/images/rails.png +0 -0
  18. data/test/rails/app/assets/javascripts/application.js +15 -0
  19. data/test/rails/app/assets/stylesheets/application.css +13 -0
  20. data/test/rails/app/controllers/application_controller.rb +17 -0
  21. data/test/rails/app/helpers/application_helper.rb +2 -0
  22. data/test/rails/app/views/application/content_for.html.mab +6 -0
  23. data/test/rails/app/views/application/normal.html.mab +2 -0
  24. data/test/rails/app/views/application/variables.html.mab +2 -0
  25. data/test/rails/app/views/layouts/application.html.mab +15 -0
  26. data/test/rails/config.ru +4 -0
  27. data/test/rails/config/application.rb +54 -0
  28. data/test/rails/config/boot.rb +6 -0
  29. data/test/rails/config/environment.rb +5 -0
  30. data/test/rails/config/environments/development.rb +27 -0
  31. data/test/rails/config/environments/production.rb +67 -0
  32. data/test/rails/config/environments/test.rb +29 -0
  33. data/test/rails/config/initializers/backtrace_silencers.rb +7 -0
  34. data/test/rails/config/initializers/inflections.rb +15 -0
  35. data/test/rails/config/initializers/mime_types.rb +5 -0
  36. data/test/rails/config/initializers/secret_token.rb +7 -0
  37. data/test/rails/config/initializers/session_store.rb +8 -0
  38. data/test/rails/config/initializers/wrap_parameters.rb +14 -0
  39. data/test/rails/config/locales/en.yml +5 -0
  40. data/test/rails/config/routes.rb +3 -0
  41. data/test/rails/script/rails +6 -0
  42. data/test/rails/test/helper.rb +7 -0
  43. data/test/rails/test/test_mab.rb +40 -0
  44. data/test/test_mab_builder.rb +56 -0
  45. data/test/test_mab_indentation.rb +66 -0
  46. data/test/test_mab_kernel_method.rb +10 -0
  47. data/test/test_mab_mixin.rb +250 -0
  48. metadata +118 -0
@@ -0,0 +1,20 @@
1
+ module Mab
2
+ class RailsBuilder < Builder
3
+ def content_for(*args)
4
+ blk = proc do |*a|
5
+ mab { yield(*a) }.html_safe
6
+ end if block_given?
7
+
8
+ @_helper.send(:content_for, *args, &blk)
9
+ end
10
+ end
11
+
12
+ class RailsHandler
13
+ def call(template)
14
+ "::Mab::RailsBuilder.new({}, self) { #{template.source} }.to_s"
15
+ end
16
+ end
17
+
18
+ ::ActionView::Template.register_template_handler :mab, RailsHandler.new
19
+ end
20
+
@@ -0,0 +1,42 @@
1
+ class MabTemplate < Tilt::Template
2
+ def self.builder_class
3
+ @builder_class ||= Class.new(Mab::Builder) do
4
+ def __capture_mab_tilt__(&block)
5
+ __run_mab_tilt__ do
6
+ text capture(&block)
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ def prepare
13
+ end
14
+
15
+ def evaluate(scope, locals, &block)
16
+ builder = self.class.builder_class.new({}, scope)
17
+
18
+ locals.each do |local, value|
19
+ (class << builder; self end).send(:define_method, local, Proc.new { value })
20
+ end
21
+
22
+ if data.kind_of? Proc
23
+ (class << builder; self end).send(:define_method, :__run_mab_tilt__, &data)
24
+ else
25
+ builder.instance_eval <<-CODE, __FILE__, __LINE__
26
+ def __run_mab_tilt__
27
+ capture(&Proc.new {#{data}})
28
+ end
29
+ CODE
30
+ end
31
+
32
+ if block
33
+ builder.__capture_mab_tilt__(&block)
34
+ else
35
+ builder.__run_mab_tilt__
36
+ end
37
+
38
+ builder
39
+ end
40
+ end
41
+
42
+ Tilt.register MabTemplate, 'mab'
@@ -0,0 +1,4 @@
1
+ module Mab
2
+ VERSION = "0.0.4"
3
+ end
4
+
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.dirname(__FILE__) + '/lib/mab/version'
3
+ require 'date'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'mab-cj'
7
+ s.version = Mab::VERSION
8
+ s.date = Date.today.to_s
9
+
10
+ s.authors = ['Magnus Holm']
11
+ s.email = ['judofyr@gmail.com']
12
+ s.summary = 'Markup as Ruby'
13
+
14
+ s.require_paths = %w(lib)
15
+ s.files = Dir["**/*"]
16
+
17
+ s.add_development_dependency('rake')
18
+ s.add_development_dependency('minitest')
19
+ end
20
+
@@ -0,0 +1,4 @@
1
+ require 'minitest/unit'
2
+ require 'minitest/autorun'
3
+ require 'mab'
4
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,17 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+
4
+ def normal
5
+ end
6
+
7
+ def no_layout
8
+ render :normal, :layout => false
9
+ end
10
+
11
+ def variables
12
+ @hello = "Hello world!"
13
+ end
14
+
15
+ def content_for
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,6 @@
1
+ content_for :page_heading do
2
+ h1 "Heading"
3
+ end
4
+
5
+ h2 "Sub"
6
+
@@ -0,0 +1,2 @@
1
+ h1 "Hello Mab!"
2
+
@@ -0,0 +1,15 @@
1
+ doctype!
2
+ html do
3
+ head do
4
+ title "Dummy"
5
+ end
6
+
7
+ body do
8
+ text! yield :page_heading
9
+
10
+ div.content do
11
+ text! yield
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,54 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "action_controller/railtie"
4
+ require "rails/test_unit/railtie"
5
+
6
+ require "mab"
7
+
8
+ if defined?(Bundler)
9
+ # If you precompile assets before deploying to production, use this line
10
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
11
+ # If you want your assets lazily compiled in production, use this line
12
+ # Bundler.require(:default, :assets, Rails.env)
13
+ end
14
+
15
+ module Dummy
16
+ class Application < Rails::Application
17
+ # Settings in config/environments/* take precedence over those specified here.
18
+ # Application configuration should go into files in config/initializers
19
+ # -- all .rb files in that directory are automatically loaded.
20
+
21
+ # Custom directories with classes and modules you want to be autoloadable.
22
+ # config.autoload_paths += %W(#{config.root}/extras)
23
+
24
+ # Only load the plugins named here, in the order given (default is alphabetical).
25
+ # :all can be used as a placeholder for all plugins not explicitly named.
26
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
27
+
28
+ # Activate observers that should always be running.
29
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
30
+
31
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
32
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
33
+ # config.time_zone = 'Central Time (US & Canada)'
34
+
35
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
36
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
37
+ # config.i18n.default_locale = :de
38
+
39
+ # Configure the default encoding used in templates for Ruby 1.9.
40
+ config.encoding = "utf-8"
41
+
42
+ # Configure sensitive parameters which will be filtered from the log file.
43
+ config.filter_parameters += [:password]
44
+
45
+ # Enable escaping HTML in JSON.
46
+ config.active_support.escape_html_entities_in_json = true
47
+
48
+ # Enable the asset pipeline
49
+ config.assets.enabled = true
50
+
51
+ # Version of your assets, change this if you want to expire all your assets
52
+ config.assets.version = '1.0'
53
+ end
54
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,27 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Print deprecation notices to the Rails logger
17
+ config.active_support.deprecation = :log
18
+
19
+ # Only use best-standards-support built into browsers
20
+ config.action_dispatch.best_standards_support = :builtin
21
+
22
+ # Do not compress assets
23
+ config.assets.compress = false
24
+
25
+ # Expands the lines which load the assets
26
+ config.assets.debug = true
27
+ end
@@ -0,0 +1,67 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ # Compress JavaScripts and CSS
15
+ config.assets.compress = true
16
+
17
+ # Don't fallback to assets pipeline if a precompiled asset is missed
18
+ config.assets.compile = false
19
+
20
+ # Generate digests for assets URLs
21
+ config.assets.digest = true
22
+
23
+ # Defaults to nil and saved in location specified by config.assets.prefix
24
+ # config.assets.manifest = YOUR_PATH
25
+
26
+ # Specifies the header that your server uses for sending files
27
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
29
+
30
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31
+ # config.force_ssl = true
32
+
33
+ # See everything in the log (default is :info)
34
+ # config.log_level = :debug
35
+
36
+ # Prepend all log lines with the following tags
37
+ # config.log_tags = [ :subdomain, :uuid ]
38
+
39
+ # Use a different logger for distributed setups
40
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
41
+
42
+ # Use a different cache store in production
43
+ # config.cache_store = :mem_cache_store
44
+
45
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
46
+ # config.action_controller.asset_host = "http://assets.example.com"
47
+
48
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
49
+ # config.assets.precompile += %w( search.js )
50
+
51
+ # Disable delivery errors, bad email addresses will be ignored
52
+ # config.action_mailer.raise_delivery_errors = false
53
+
54
+ # Enable threaded mode
55
+ # config.threadsafe!
56
+
57
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
58
+ # the I18n.default_locale when a translation can not be found)
59
+ config.i18n.fallbacks = true
60
+
61
+ # Send deprecation notices to registered listeners
62
+ config.active_support.deprecation = :notify
63
+
64
+ # Log the query plan for queries taking more than this (works
65
+ # with SQLite, MySQL, and PostgreSQL)
66
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
67
+ end
@@ -0,0 +1,29 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Configure static asset server for tests with Cache-Control for performance
11
+ config.serve_static_assets = true
12
+ config.static_cache_control = "public, max-age=3600"
13
+
14
+ # Log error messages when you accidentally call methods on nil
15
+ config.whiny_nils = true
16
+
17
+ # Show full error reports and disable caching
18
+ config.consider_all_requests_local = true
19
+ config.action_controller.perform_caching = false
20
+
21
+ # Raise exceptions instead of rendering exception templates
22
+ config.action_dispatch.show_exceptions = false
23
+
24
+ # Disable request forgery protection in test environment
25
+ config.action_controller.allow_forgery_protection = false
26
+
27
+ # Print deprecation notices to the stderr
28
+ config.active_support.deprecation = :stderr
29
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
11
+ #
12
+ # These inflection rules are supported but not enabled by default:
13
+ # ActiveSupport::Inflector.inflections do |inflect|
14
+ # inflect.acronym 'RESTful'
15
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = '623959e722473332aa626a9e3508ec9c05642609d7440408ece5c2e75a71404999a5b220b27a0b864a09a10180bcb13ed3f3a4bb8e7f90c33f894a7ec9aa9571'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store