mab-0.0.3/0000755000004100000410000000000012154154304012300 5ustar www-datawww-datamab-0.0.3/test/0000755000004100000410000000000012154154304013257 5ustar www-datawww-datamab-0.0.3/test/test_mab_builder.rb0000644000004100000410000000170712154154304017115 0ustar www-datawww-datarequire 'helper' class TestMabBuilder < MiniTest::Unit::TestCase def test_assigns b = Mab::Builder.new(:title => 'Mab') do title @title end assert_equal 'Mab', b.to_s end def test_capture b = Mab::Builder.new do %w[name address].map do |key| mab do p key end end.join('
') end assert_equal "

name


address

", b.to_s end def test_helper obj = Class.new { def initialize @a = 1 @b = 2 end def c; @a + @b end }.new b = Mab::Builder.new({}, obj) do p @a p @b p c end assert_equal '

1

2

3

', b.to_s end def test_pretty b = Mab::PrettyBuilder.new do doctype! html do body do h1 "Nice" end end end assert_equal "\n\n \n

Nice

\n \n", b.to_s end end mab-0.0.3/test/rails/0000755000004100000410000000000012154154304014371 5ustar www-datawww-datamab-0.0.3/test/rails/app/0000755000004100000410000000000012154154304015151 5ustar www-datawww-datamab-0.0.3/test/rails/app/assets/0000755000004100000410000000000012154154304016453 5ustar www-datawww-datamab-0.0.3/test/rails/app/assets/stylesheets/0000755000004100000410000000000012154154304021027 5ustar www-datawww-datamab-0.0.3/test/rails/app/assets/stylesheets/application.css0000644000004100000410000000104212154154304024041 0ustar www-datawww-data/* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the top of the * compiled file, but it's generally better to create a new file per style scope. * *= require_self *= require_tree . */ mab-0.0.3/test/rails/app/assets/javascripts/0000755000004100000410000000000012154154304021004 5ustar www-datawww-datamab-0.0.3/test/rails/app/assets/javascripts/application.js0000644000004100000410000000120112154154304023637 0ustar www-datawww-data// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // the compiled file. // // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD // GO AFTER THE REQUIRES BELOW. // //= require jquery //= require jquery_ujs //= require_tree . mab-0.0.3/test/rails/app/assets/images/0000755000004100000410000000000012154154304017720 5ustar www-datawww-datamab-0.0.3/test/rails/app/assets/images/rails.png0000644000004100000410000001476612154154304021556 0ustar www-datawww-dataPNG  IHDR2@X${tEXtSoftwareAdobe ImageReadyqe<IDATxڬ[ \eR֮^;Iwga@`gGgDgtqDFqFDqF@NRU]˫|_-Qy^Ǹ.݋0W_6kbf̻ܸ6<4 w5~*r?9m&"M7@vm' {_S)Vi\WG?իjMd@ lDLX鸺W-TU+@EPo\&*Rnn, fDWrX|3M=\EJB[d6A'=tx^$a86̈{, ϱPepN*_W_3o;ޥ(0E:i6eXnhGf"L|S+(+.gФg=Ych=m#V_#}Ǫ|tR D8VՄM~xg!ni%Dy( B,{(Np$3iر$h.@e[a'eJԂyϠ4>H*MHQ(Jgt-֢QI ^d„@s-'- 51{'0 |n4ۉh{V@ܩw"BT =rzqPpBHȃ?ň ]-qpgsPiSӪg`jn)m 御B2L.x!jJP! K/\ ʮRB[09Trӈu. uH$ DDQ+:ݘٻ 3/nލ%Sjm2!&D/[EHwW A-RR!PeuHim"t6lFgЫ-O.1?ƞksX~VtmZJR11Nu&<⽩,Tb,`w WPx-G5 `մ/5pbAtIVJ_]0/DiH=ô#*77-3 VuQ0.pݔ%yw hљW0),2$b6&I/@bj$I(fx' JnO"`<-/LѮ%^ȫͶn2wҗ2}}XսL'Q-,m/ꤋ4#0Q&00NKrsA,Aײ)aIEC(ERK{8Ȭ[y?iI5$%f{}u F 1~;v1l'@F 'IF'm!K7"&]w 15#4Vižn[v 8Ě)>C=LBo~/3% wF4֓ʿ8>bWX@bb@IzP9IvFfQL!2cEP(se4~5RhAŽ90_? cMEteVOaOr B]pȱؓ"Eyx: NJ)bl׋hYuTdԫw=آMgwVPOFΒ25-TD[Z2>]V,xӛIOƅ)Jͺ[)?cn28p#(mk+./phʮQ6?w7HIoSj)1<#-N9O1ͰސkIKr:(ŗ;rR&<93v@w(w:~:TFSޒ" ՊTdT9PIb3JzTQׄBP23ƵW*|@^)Qw?Iq =,<@ B8);50H-=T SA@@f5r[T%#c|Z&w(B)tDQ%vyC(,Ɵ|ʰi&<#u:3EHkzд)ndF>1V2kFGYL KMQlR&TB,igv8]C8Sf#ą4Q'?,= aV9WEXYrr*!cƯ~),=yџ]jlGeE̺5r_2Ԏ}d"a]0M9PZG17nE"Rr\YQ)!|5U(d=^ŗo8+2NU6jB[B5V.]ŲW/^䩬 ;Y"Vi$2ٲ_c(F^Egq{CP/ #K8Y+Q M1>ܞAߏ,gytޕn,zE$V.v.PyLapG9Tn:uiRZ! zI0?Џ1u#$6ɱGMhFdtd|~d\O9Ij**zD؍b)PBҽh-q ql%/{Gz*d7=QS]:RQbUMPᒯ$% du] XefQz$('ИZH#ARXDB ~`0.F|XXK)wFolzyhߚKz>.&n EjU,2' &iw[d[ V)*Qavl QDit[VIQhR@$)y~m|>?cJ+VH'6? 7 i.XH8Fި)dAYUBjE".4w-?l2Y.RjWD@Bج.߆s[H-gASF3Fj]آBP떬_>M%bt ?_rլ -h]r_ž[nȶQ+Gԭ_\Ê Z٦fet(|U('.g VFEN9}Ll4T&nto¨Ӓ X F "_fYzF~y& Gu]$O[v#].@$VA`ⱧTѰZ[2u+/mUC_ TnyѠ |l\ M"G[R$d|:ěFIire"ٵt,+ی1Z11udt*K2 sd; [)xW.z2jTh#DV\NO &e_vU2B^%0FH(/ԘI2>=L]dv UUpk"ijB$,O-0y<}~*T5LErE4B߳XXN:<9>Ed -V*uBLsN**JxRU辖,T( Gu @ůY{u|CJF(OLbnմiKhpFtx8#9FsFڋDTAn1veF^M ^kf.ĆݠVʓǰ3JaY@n&jLl:McӚ…vu?9w!/~#hM ڛ ̴nMA}m W,)(î.N y%$*={P9c DzH>Blu޾K78x->V,'JU \L]l>W*r-hXf~oI Z3f玱>vN3 uZTgg}Վ363:.g /-H+"PKۉSZ4Z_GlXMc7";ҿ (5fMUCOF6 CNft>$S1VaR&4) ٗay]%W A*|gX{Qc>iTX1F M`|![$P4ʊ$#,dɌ(?KTJR۸S%C7jHb浃j+N$,[.@˹_ ?.3ĵH"U$Z^ X02!Kc 8q.NMI6N&3n8exoWfPIJB<pREAdo$*m)e9D 5X[T$LΠ:]C$n#mC[P~Yt*d?\q^WXs!E-2#_mw8;2!vw:DUn$)GiGn3_o EZE3k-EHv.OûzE>"֛}l\/-nرQHԽab*#K׋eIƳd#G et\ ,:MێÜIC}m ٽO?eb%ːٰStB|Aznaz*FlQ/K uu*1wDvE֯SJTK;(4kƣ;v2P9`k{?~_[hʢ^9фǡ;m|]o9<#jz\wD,8V]]%K9er懇0n^FcI>`Ub+kօO1|NO]t+,Ȑl_ˮ6 ĒDbrz^pe7^[aþo確jN+xsNC߅wμ7|za2, omrbZ~,pN>;?Y,z[u◿jq 4aqڶNu6Zid@h!!F9#,#UrOa0=Då ,,,bE#ȮX3ªޏ=a< =&_~ ٵѽacj񫒆LsXuXB (wzEk_QIف*4'ѣSl{.,p۵2`jp^؇nZXPź^]wމ]aQ-oI5O3a] _wb ŭL]$"|sԩȬ= VсLIUbYY搮͢I$tf$2|r;~'GSXkᇦԭF4b4 xo[,04F~<}ۭR%myb׾\mlO.4}tE\7}M)tՉ13xF [-26t䢄&E"9;ٜrq e)K!:bwY }g;Jר)5D$!Kɤ9߫-K$$ hlDUFF J{s2R6rC&&0;@>]/Z3E,k;( 2^09 false end def variables @hello = "Hello world!" end def content_for end end mab-0.0.3/test/rails/test/0000755000004100000410000000000012154154304015350 5ustar www-datawww-datamab-0.0.3/test/rails/test/helper.rb0000644000004100000410000000030112154154304017146 0ustar www-datawww-data# Configure Rails Envinronment ENV["RAILS_ENV"] = "test" require File.expand_path("../../config/environment.rb", __FILE__) require "rails/test_help" Rails.backtrace_cleaner.remove_silencers! mab-0.0.3/test/rails/test/test_mab.rb0000644000004100000410000000231612154154304017475 0ustar www-datawww-datarequire File.expand_path('../helper', __FILE__) class TestMab < ActionDispatch::IntegrationTest test "normal view" do get "application/normal" assert_response :success assert_template "application/normal" assert_template "layouts/application" assert_html "

Hello Mab!

" end test "no layout" do get "application/no_layout" assert_response :success assert_template "application/normal" assert_equal "

Hello Mab!

", @response.body end test "variables" do get "application/variables" assert_response :success assert_template "application/variables" assert_template "layouts/application" assert_html "

Hello world!

" end test "content for" do get "application/content_for" assert_response :success assert_template "application/content_for" assert_template "layouts/application" assert_html "

Sub

", :heading => "

Heading

" end def assert_html(expected, options = {}) expected = "Dummy#{options[:heading]}
#{expected}
" unless options[:skip_layout] assert_equal expected, @response.body end end mab-0.0.3/test/rails/script/0000755000004100000410000000000012154154304015675 5ustar www-datawww-datamab-0.0.3/test/rails/script/rails0000755000004100000410000000044712154154304016742 0ustar www-datawww-data#!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands' mab-0.0.3/test/rails/Rakefile0000644000004100000410000000041612154154304016037 0ustar www-datawww-data#!/usr/bin/env rake # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require File.expand_path('../config/application', __FILE__) Dummy::Application.load_tasks mab-0.0.3/test/rails/config/0000755000004100000410000000000012154154304015636 5ustar www-datawww-datamab-0.0.3/test/rails/config/application.rb0000644000004100000410000000423712154154304020474 0ustar www-datawww-datarequire File.expand_path('../boot', __FILE__) require "action_controller/railtie" require "rails/test_unit/railtie" require "mab" if defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.require(:default, :assets, Rails.env) end module Dummy class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Custom directories with classes and modules you want to be autoloadable. # config.autoload_paths += %W(#{config.root}/extras) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. # config.plugins = [ :exception_notification, :ssl_requirement, :all ] # Activate observers that should always be running. # config.active_record.observers = :cacher, :garbage_collector, :forum_observer # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. # config.time_zone = 'Central Time (US & Canada)' # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de # Configure the default encoding used in templates for Ruby 1.9. config.encoding = "utf-8" # Configure sensitive parameters which will be filtered from the log file. config.filter_parameters += [:password] # Enable escaping HTML in JSON. config.active_support.escape_html_entities_in_json = true # Enable the asset pipeline config.assets.enabled = true # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' end end mab-0.0.3/test/rails/config/routes.rb0000644000004100000410000000012412154154304017501 0ustar www-datawww-dataDummy::Application.routes.draw do get ':controller(/:action(/:id(.:format)))' end mab-0.0.3/test/rails/config/locales/0000755000004100000410000000000012154154304017260 5ustar www-datawww-datamab-0.0.3/test/rails/config/locales/en.yml0000644000004100000410000000032612154154304020406 0ustar www-datawww-data# Sample localization file for English. Add more files in this directory for other locales. # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points. en: hello: "Hello world" mab-0.0.3/test/rails/config/environment.rb0000644000004100000410000000022512154154304020526 0ustar www-datawww-data# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Dummy::Application.initialize! mab-0.0.3/test/rails/config/initializers/0000755000004100000410000000000012154154304020344 5ustar www-datawww-datamab-0.0.3/test/rails/config/initializers/session_store.rb0000644000004100000410000000063212154154304023571 0ustar www-datawww-data# Be sure to restart your server when you modify this file. Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rails generate session_migration") # Dummy::Application.config.session_store :active_record_store mab-0.0.3/test/rails/config/initializers/secret_token.rb0000644000004100000410000000076012154154304023361 0ustar www-datawww-data# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Dummy::Application.config.secret_token = '623959e722473332aa626a9e3508ec9c05642609d7440408ece5c2e75a71404999a5b220b27a0b864a09a10180bcb13ed3f3a4bb8e7f90c33f894a7ec9aa9571' mab-0.0.3/test/rails/config/initializers/mime_types.rb0000644000004100000410000000031512154154304023043 0ustar www-datawww-data# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone mab-0.0.3/test/rails/config/initializers/inflections.rb0000644000004100000410000000102512154154304023204 0ustar www-datawww-data# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end # # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections do |inflect| # inflect.acronym 'RESTful' # end mab-0.0.3/test/rails/config/initializers/backtrace_silencers.rb0000644000004100000410000000062412154154304024661 0ustar www-datawww-data# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. # Rails.backtrace_cleaner.remove_silencers! mab-0.0.3/test/rails/config/initializers/wrap_parameters.rb0000644000004100000410000000072412154154304024070 0ustar www-datawww-data# Be sure to restart your server when you modify this file. # # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters :format => [:json] end # Disable root element in JSON by default. ActiveSupport.on_load(:active_record) do self.include_root_in_json = false end mab-0.0.3/test/rails/config/boot.rb0000644000004100000410000000027712154154304017134 0ustar www-datawww-datarequire 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) mab-0.0.3/test/rails/config/environments/0000755000004100000410000000000012154154304020365 5ustar www-datawww-datamab-0.0.3/test/rails/config/environments/production.rb0000644000004100000410000000465712154154304023114 0ustar www-datawww-dataDummy::Application.configure do # Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = false # Compress JavaScripts and CSS config.assets.compress = true # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false # Generate digests for assets URLs config.assets.digest = true # Defaults to nil and saved in location specified by config.assets.prefix # config.assets.manifest = YOUR_PATH # Specifies the header that your server uses for sending files # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # See everything in the log (default is :info) # config.log_level = :debug # Prepend all log lines with the following tags # config.log_tags = [ :subdomain, :uuid ] # Use a different logger for distributed setups # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) # Use a different cache store in production # config.cache_store = :mem_cache_store # Enable serving of images, stylesheets, and JavaScripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) # config.assets.precompile += %w( search.js ) # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false # Enable threaded mode # config.threadsafe! # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true # Send deprecation notices to registered listeners config.active_support.deprecation = :notify # Log the query plan for queries taking more than this (works # with SQLite, MySQL, and PostgreSQL) # config.active_record.auto_explain_threshold_in_seconds = 0.5 end mab-0.0.3/test/rails/config/environments/test.rb0000644000004100000410000000223012154154304021666 0ustar www-datawww-dataDummy::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! config.cache_classes = true # Configure static asset server for tests with Cache-Control for performance config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" # Log error messages when you accidentally call methods on nil config.whiny_nils = true # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false # Raise exceptions instead of rendering exception templates config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false # Print deprecation notices to the stderr config.active_support.deprecation = :stderr end mab-0.0.3/test/rails/config/environments/development.rb0000644000004100000410000000171712154154304023242 0ustar www-datawww-dataDummy::Application.configure do # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false # Print deprecation notices to the Rails logger config.active_support.deprecation = :log # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin # Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true end mab-0.0.3/test/rails/config.ru0000644000004100000410000000023312154154304016204 0ustar www-datawww-data# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Dummy::Application mab-0.0.3/test/test_mab_mixin.rb0000644000004100000410000001142412154154304016610 0ustar www-datawww-datarequire 'helper' class TestMabMixin < MiniTest::Unit::TestCase def setup super @obj = Object.new end def test_tag @obj.extend Mab::Mixin assert_equal '
', @obj.mab { tag! :br } assert_equal '

', @obj.mab { tag! :br, nil } assert_equal '

Hello

', @obj.mab { tag! :p, 'Hello' } assert_equal '

Hello

', @obj.mab { tag! :p, 'Hello', :class => "intro" } assert_equal '


', @obj.mab { tag! :p do tag! :br end } assert_equal '
', @obj.mab { tag! :br, :class => 'intro' } assert_equal '
', @obj.mab { tag! :br, :class => nil } assert_raises Mab::Mixin::Error do @obj.mab do tag! :p, "content" do "and block" end end end end def test_multile_attrs @obj.extend Mab::Mixin assert_equal '
', @obj.mab { tag! :br, { :class => "intro" }, { :id => "yay" } } end def test_escaping @obj.extend Mab::Mixin assert_equal '

&

', @obj.mab { tag! :p, '&' } assert_equal '

&

', @obj.mab { tag! :p do '&' end } assert_equal '&', @obj.mab { text '&' } end def test_chaining @obj.extend Mab::Mixin assert_equal '

Hello

', @obj.mab { tag!(:p).intro.first!('Hello') } assert_equal '
Hello
', @obj.mab { tag!(:div).content("Hello") } assert_raises(Mab::Mixin::Error) do @obj.mab do tag!(:p).intro('Hello').first!('Hello') end end assert_raises(Mab::Mixin::Error) do @obj.mab do tag!(:p).intro(:class => 'bar').first!('Hello') end end end def test_html5_chaining @obj.extend Mab::Mixin::HTML5 assert_equal '

Hello

', @obj.mab { p.intro.first!('Hello') } end def test_mab_done @obj.extend Mab::Mixin def @obj.mab_done(tag) tag._attributes = { :nope => 123 } end assert_equal '


', @obj.mab { tag! :p, :hello => :world do tag!(:br).klass(:hello => :world) end } end def test_mab_done_ignore_block @obj.extend Mab::Mixin def @obj.mab_done(tag) tag._block = nil tag._content = '' end assert_equal '

', @obj.mab { tag! :p do tag!(:br).klass(:hello => :world) end } end def test_mab_done_wrap_block @obj.extend Mab::Mixin def @obj.mab_done(tag) tag._block do |blk| tag! :p, 'nice' blk.call end if tag._name == :body end assert_equal "

nice


", @obj.mab { tag! :body do tag! :br end } end def test_mab_insert @obj.extend Mab::Mixin def @obj.mab_insert(tag) tag._name = :nope if tag.respond_to?(:_name=) super end assert_equal '', @obj.mab { tag! :br } end def test_stringification @obj.extend Mab::Mixin assert_equal '

My name is: Bob

', @obj.mab { tag!(:h1) do "My name is: #{tag!(:span, 'Bob')}" end } assert_equal '

Hello | Hello

', @obj.mab { tag!(:h1) do s = tag!(:span, 'Hello') tag!(:div) do [s, s].join(' | ') end end } end def test_xml @obj.extend Mab::Mixin @obj.mab_options[:xml] = true assert_equal '



hello
', @obj.mab { tag! :br tag! :br, '' tag! :br, 'hello' } end def test_html5 @obj.extend Mab::Mixin::HTML5 assert_equal '


', @obj.mab { doctype! html do body do p br end end } assert_raises Mab::Mixin::Error do @obj.mab { br { } } end assert_raises Mab::Mixin::Error do @obj.mab { br "hello" } end assert_raises Mab::Mixin::Error do @obj.mab { br.klass "hello" } end assert_includes [ '', '', ], @obj.mab { input.text :value => 'name' } end def test_xhtml5 @obj.extend Mab::Mixin::XHTML5 assert_equal '


', @obj.mab { doctype! html do body do p br end end } assert_raises Mab::Mixin::Error do @obj.mab { br { } } end assert_raises Mab::Mixin::Error do @obj.mab { br "hello" } end end def test_core_xml @obj.extend Mab::Mixin::XML assert_equal '
', @obj.mab { tag! :br } end end mab-0.0.3/test/helper.rb0000644000004100000410000000010212154154304015054 0ustar www-datawww-datarequire 'minitest/unit' require 'minitest/autorun' require 'mab' mab-0.0.3/test/test_mab_kernel_method.rb0000644000004100000410000000033312154154304020301 0ustar www-datawww-datarequire 'helper' class TestMabKernelMethod < MiniTest::Unit::TestCase def test_kernel_method require 'mab/kernel_method' @a = 1 assert_equal "

\n

3

\n

", mab { p { p { @a + 2 } } } end end mab-0.0.3/test/test_mab_indentation.rb0000644000004100000410000000177712154154304020012 0ustar www-datawww-datarequire 'helper' class TestMabIndentation < MiniTest::Unit::TestCase def setup super @obj = Object.new @obj.extend Mab::Mixin @obj.extend Mab::Indentation end def test_simple assert_equal "

Hello

", @obj.mab { tag! :p, 'Hello' } end def test_block assert_equal "

\n Hello\n

", @obj.mab { tag!(:p) { text 'Hello' } } end def test_chaining res = <

HTML assert_equal res, @obj.mab { tag!(:p).hello do tag! :br end } end def test_reindent res = < Hello World

HTML assert_equal res, @obj.mab { tag! :p do reindent! "Hello\nWorld" end } end def test_stringification res = <
Hello | Hello
HTML assert_equal res, @obj.mab { tag!(:h1) do s = tag!(:span, 'Hello') tag!(:div) do [s, s].join(' | ') end end } end end mab-0.0.3/README.md0000644000004100000410000000656012154154304013566 0ustar www-datawww-dataMab (Markup as Ruby) ==================== Mab let's you write HTML in plain Ruby: ```ruby doctype! html do head do link :rel => 'stylesheet', :href => 'style.css' script :src => 'jquery.js' end body :id => :frontpage do h1 'Hello World', :class => :main end end ``` Syntax ------ ### 1. Tags and Attributes There are four basic forms: ```ruby tagname(content) tagname(content, attributes) tagname do content end tagname(attributes) do content end ``` Example: ```ruby doctype! html do head do link :rel => 'stylesheet', :href => 'style.css' script :src => 'jquery.js' end body :id => :frontpage do h1 'Hello World', :class => :main end end ``` Which results in: ```html

Hello World

``` Notice how Mab knows that script tag must have content, so although you didn't specify anything it closed the tag for you. ### 2. Element Classes and IDs You can easily add classes and IDs by hooking methods onto the container: ```ruby body.frontpage! do h1.main 'Hello World' end ``` Which results in: ```html

Hello World

``` You can mix and match as you'd like (`div.klass.klass1.id!`), but you can only provide content and attributes on the *last* call: ```ruby # This is not valid: form(:action => :post).world do input end # But this is: form.world(:action => :post) do input end ``` ### 3. Escape or Not Escape Mab uses a very simple convention for escaping: Strings as *arguments* gets escaped, strings in *blocks* don't: ```ruby div.comment "" #
<script>alert(1)</script>
div.comment { "I love you" } #
I love you
``` Be aware that Mab ignores the string in a block if there's other tags there: ```ruby div.comment do div.author "BitPuffin" "

Silence!

" end ``` The p tag above won't appear in the output. ### 4. Text Sometimes you need to insert plain text: ```ruby p.author do text 'Written by ' a 'Bluebie', :href => 'http://creativepony.com/' end ``` Which results in: ```html

Written by Bluebie

``` There's also `text!` which doesn't escape: ```ruby p.author do text! 'Written by' a 'Bluebie', :href => 'http://creativepony.com/' ``` Invoking Mab ------------ Using #mab: ```ruby require 'mab/kernel_method' str = mab do doctype! html do # ... end end ``` Using Mab::Builder (or Mab::PrettyBuilder if you want indentation): ```ruby class Person attr_reader :name def initialize(name) @name = name end def awesome?; true end end # Assign instance variables: Mab::Builder.new(:person => Person.new('BitBuffin')) do if @person.awesome? h1 @person.name else p @person.name end end.to_s # Use helper (methods and instance variables will be available): Mab::Builder.new({}, Person.new('BitPuffin')) do if awesome? h1 @name else p @name end end.to_s ``` Extending an object (*advanced usage*): ```ruby r = Object.new r.extend Mab::Mixin::HTML5 r.extend Mab::Indentation r.mab do doctype! html do # ... end end ``` mab-0.0.3/Rakefile0000644000004100000410000000044512154154304013750 0ustar www-datawww-datarequire 'rake/testtask' task :default => :test task :test => 'test:core' namespace 'test' do Rake::TestTask.new('core') do |t| t.libs << 'lib' << 'test' end Rake::TestTask.new('rails') do |t| t.libs << 'lib' t.test_files = FileList['test/rails/test/test_*.rb'] end end mab-0.0.3/mab.gemspec0000644000004100000410000000074412154154304014411 0ustar www-datawww-data# -*- encoding: utf-8 -*- require File.dirname(__FILE__) + '/lib/mab/version' require 'date' Gem::Specification.new do |s| s.name = 'mab' s.version = Mab::VERSION s.date = Date.today.to_s s.authors = ['Magnus Holm'] s.email = ['judofyr@gmail.com'] s.summary = 'Markup as Ruby' s.require_paths = %w(lib) s.files = Dir["**/*"] s.add_development_dependency('rake') s.add_development_dependency('minitest') end mab-0.0.3/checksums.yaml.gz0000444000004100000410000000065112154154304015570 0ustar www-datawww-data8Q0 ٹwI20&$( ]B3?Jg0'cIwӷۚ=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: minitest requirement: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' description: email: - judofyr@gmail.com executables: [] extensions: [] extra_rdoc_files: [] files: - COPYING - Gemfile - Gemfile.lock - lib/mab/builder.rb - lib/mab/indentation.rb - lib/mab/kernel_method.rb - lib/mab/mixin.rb - lib/mab/rails.rb - lib/mab/version.rb - lib/mab.rb - mab.gemspec - Rakefile - README.md - test/helper.rb - test/rails/app/assets/images/rails.png - test/rails/app/assets/javascripts/application.js - test/rails/app/assets/stylesheets/application.css - test/rails/app/controllers/application_controller.rb - test/rails/app/helpers/application_helper.rb - test/rails/app/views/application/content_for.html.mab - test/rails/app/views/application/normal.html.mab - test/rails/app/views/application/variables.html.mab - test/rails/app/views/layouts/application.html.mab - test/rails/config/application.rb - test/rails/config/boot.rb - test/rails/config/environment.rb - test/rails/config/environments/development.rb - test/rails/config/environments/production.rb - test/rails/config/environments/test.rb - test/rails/config/initializers/backtrace_silencers.rb - test/rails/config/initializers/inflections.rb - test/rails/config/initializers/mime_types.rb - test/rails/config/initializers/secret_token.rb - test/rails/config/initializers/session_store.rb - test/rails/config/initializers/wrap_parameters.rb - test/rails/config/locales/en.yml - test/rails/config/routes.rb - test/rails/config.ru - test/rails/Rakefile - test/rails/script/rails - test/rails/test/helper.rb - test/rails/test/test_mab.rb - test/test_mab_builder.rb - test/test_mab_indentation.rb - test/test_mab_kernel_method.rb - test/test_mab_mixin.rb homepage: licenses: [] metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.0.2 signing_key: specification_version: 4 summary: Markup as Ruby test_files: [] mab-0.0.3/COPYING0000644000004100000410000000204512154154304013334 0ustar www-datawww-dataCopyright (c) 2012 Magnus Holm Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. mab-0.0.3/Gemfile0000644000004100000410000000023412154154304013572 0ustar www-datawww-datasource 'https://rubygems.org/' group :development do gem "rake" end group :test do gem "minitest" end if ENV['RAILS'] gem 'rails', '= 3.2.12' end mab-0.0.3/lib/0000755000004100000410000000000012154154304013046 5ustar www-datawww-datamab-0.0.3/lib/mab/0000755000004100000410000000000012154154304013605 5ustar www-datawww-datamab-0.0.3/lib/mab/rails.rb0000644000004100000410000000065312154154304015250 0ustar www-datawww-datamodule Mab class RailsBuilder < Builder def content_for(*args) blk = proc do |*a| mab { yield(*a) }.html_safe end if block_given? @_helper.send(:content_for, *args, &blk) end end class RailsHandler def call(template) "::Mab::RailsBuilder.new({}, self) { #{template.source} }.to_s" end end ::ActionView::Template.register_template_handler :mab, RailsHandler.new end mab-0.0.3/lib/mab/version.rb0000644000004100000410000000004412154154304015615 0ustar www-datawww-datamodule Mab VERSION = "0.0.3" end mab-0.0.3/lib/mab/indentation.rb0000644000004100000410000000116512154154304016451 0ustar www-datawww-datamodule Mab module Indentation def mab_insert(str) if i = @mab_context.options[:indentation] super([$/ + " " * i, str]) else @mab_context.options[:indentation] = 0 super end end def mab_done(tag) if blk = tag._block tag._block = proc do begin @mab_context.options[:indentation] += 1 blk.call ensure @mab_context.options[:indentation] -= 1 end end end super end def reindent!(str) str.split(/\r?\n/).each do |s| text! s end end end end mab-0.0.3/lib/mab/builder.rb0000644000004100000410000000151312154154304015560 0ustar www-datawww-datamodule Mab class SimpleBuilder include Mixin def initialize(assigns = {}, helper = nil, &blk) @_helper = helper @_result = [] assigns.each do |key, value| instance_variable_set(:"@#{key}", value) end if helper helper.instance_variables.each do |var| instance_variable_set(var, helper.instance_variable_get(var)) end end capture(&blk) if blk end def capture(&blk) @_result << mab(&blk) end def to_s; @_result.join end def method_missing(name, *args, &blk) if @_helper && @_helper.respond_to?(name, true) @_helper.send(name, *args, &blk) else super end end end class Builder < SimpleBuilder include HTML5 end class PrettyBuilder < Builder include Indentation end end mab-0.0.3/lib/mab/mixin.rb0000644000004100000410000001376212154154304015267 0ustar www-datawww-datarequire 'cgi' module Mab module Mixin class Error < StandardError; end class Tag attr_accessor :_name, :_content, :_attributes, :_block, :_has_content attr_reader :_options, :_context, :_instance def initialize(name, options, context, instance = nil) @_name = name @_options = options @_context = context @_instance = instance @_done = false @_content = nil @_has_content = nil @_attributes = {} @_pos = @_context.size end def _block return @_block unless block_given? current = @_block @_block = proc { yield current } end def _merge_attributes(*args) args.each do |attrs| @_attributes.merge!(attrs) end end def method_missing(name, *args, &blk) name = name.to_s if name[-1] == ?! @_attributes[:id] = name[0..-2] else if @_attributes.has_key?(:class) @_attributes[:class] += " #{name}" else @_attributes[:class] = name end end _insert(*args, &blk) end def _insert(*args, &blk) raise Error, "This tag is already closed" if @_done if !args.empty? && !args[0].is_a?(Hash) content = args.shift raise Error, "Tag doesn't allow content" if @_has_content == false @_has_content = true end if content @_content = CGI.escapeHTML(content.to_s) @_done = true end if !args.empty? _merge_attributes(*args) @_done = true end if block_given? raise Error, "Tag doesn't allow content" if @_has_content == false @_has_content = true @_block = blk @_done = true end if @_content && @_block raise Error, "Both content and _block is not allowed" end @_instance.mab_done(self) if @_done if @_block before = @_context.children res = @_block.call if before >= @_context.children @_content = res.to_s else # Turn the node into just an opening tag. @_has_content = false @_instance.mab_insert("") end end self end def to_ary() nil end def to_str() to_s end def _attrs_to_s @_attributes.inject("") do |res, (name, value)| if value value = (value == true) ? name : CGI.escapeHTML(value.to_s) res << " #{name}=\"#{value}\"" end res end end def to_s if !@_context.joining? && @_context[@_pos] @_context[@_pos] = nil @_context.children -= 1 end res = "<#{@_name}#{_attrs_to_s}" res << (@_options[:xml] && !@_block && !@_has_content ? ' />' : '>') res << "#{@_content}" if @_has_content res end end class Context < Array attr_accessor :children, :options def initialize @children = 0 @joining = false @options = {} end def <<(str) @children += 1 super(str) end def join(*) @joining = true super end def joining? @joining end end def mab_tag(name) ctx = @mab_context || raise(Error, "Tags can only be written within a `mab { }`-block") tag = Tag.new(name, mab_options, ctx, self) mab_insert(tag) tag end def tag!(name, *args, &blk) mab_tag(name)._insert(*args, &blk) end def text!(str) mab_insert(str) end def text(str) text! CGI.escapeHTML(str.to_s) end def mab(&blk) prev = defined?(@mab_context) && @mab_context ctx = @mab_context = Context.new res = instance_eval(&blk) ctx.empty? ? res : ctx.join ensure @mab_context = prev end def mab_insert(tag) ctx = @mab_context || raise(Error, 'mab { }-block required') ctx << tag end def mab_done(tag) end def mab_options @mab_options ||= {} end module XML include Mixin def mab_options @mab_options ||= super.update(:xml => true) end end module HTMLDefiners def define_tag(meth, tag) class_eval <<-EOF def #{meth}(*args, &blk) tag = mab_tag(:#{tag}) tag._has_content = true tag._insert(*args, &blk) end EOF end def define_tags(*tags) tags.flatten.each do |tag| define_tag(tag, tag) end end def define_empty_tag(meth, tag) class_eval <<-EOF def #{meth}(*args, &blk) tag = mab_tag(:#{tag}) tag._has_content = false tag._insert(*args, &blk) end EOF end def define_empty_tags(*tags) tags.flatten.each do |tag| define_empty_tag(tag, tag) end end end module HTML5 extend HTMLDefiners include Mixin define_tags %w[a abbr acronym address applet article aside audio b basefont bdi bdo big blockquote body button canvas caption center cite code colgroup datalist dd del details dfn dir div dl dt em fieldset figcaption figure font footer form frame frameset h1 h2 h3 h4 h5 h6 head header hgroup html i iframe ins kbd label legend li link map mark math menu meter nav noframes noscript object ol optgroup option output p pre progress q rp rt ruby s samp script section select small span strike strong style sub summary sup svg table tbody td textarea tfoot th thead time title tr tt u ul var video xmp] define_empty_tags %w[base link meta hr br wbr img embed param source track area col input keygen command] def doctype! text! '' end end module XHTML5 include HTML5 include XML end end end mab-0.0.3/lib/mab/kernel_method.rb0000644000004100000410000000012012154154304016743 0ustar www-datawww-datarequire 'mab' def mab(&blk) Mab::PrettyBuilder.new({}, self, &blk).to_s end mab-0.0.3/lib/mab.rb0000644000004100000410000000021112154154304014124 0ustar www-datawww-datarequire 'mab/version' require 'mab/mixin' require 'mab/indentation' require 'mab/builder' require 'mab/rails' if defined?(::ActionView) mab-0.0.3/Gemfile.lock0000644000004100000410000000020612154154304014520 0ustar www-datawww-dataGEM remote: https://rubygems.org/ specs: minitest (4.6.2) rake (10.0.3) PLATFORMS ruby DEPENDENCIES minitest rake