Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding files

  • Loading branch information...
commit 9e595f9b31b271c7e88b8759a000d96a0bdd3049 1 parent 4c1942f
Noel Rappin authored
View
BIN  .DS_Store
Binary file not shown
View
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2008 [name of plugin creator]
+
+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 OR COPYRIGHT HOLDERS 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.
View
90 README
@@ -1,13 +1,99 @@
-rails-iui
+rails_iui
========
A Rails wrapper around the iUI library for creating web applications.
-Coming soon.
+This was originally created as a set of examples for some articles that should
+be appearing soon. I'm releasing them as a plugin in the hope they'll be
+somewhat useful, even in their current partial state.
+
+4-21-2008: Still functionally incomplete, and somewhat embarrassingly, without
+automated tests.
+
+More Info
+=========
+
+Details on iUI can be found at http://code.google.com/p/iui/
+
+The URL for this repository is http://github.com/noelrappin/rails-iui/tree/master
+
+The clone URL is git://github.com/noelrappin/rails-iui.git
Example
=======
+The rails_iui plugin does three things.
+
+A series of Rake tasks will download iUI and insert it in the current Rails
+project, changing the image URLs in the CSS file to match the standard Rails
+layout.
+
+rake iui:install #download and install
+rake iui:install_compact #download and install the compact version of iui
+rake iui:clean #removes iui files
+
+The module ActionController::IphoneController adds support for recognizing
+Mobile Safari as the :iphone pseudo-MIME type.
+
+In your controller (can be ApplicationController) add the line
+
+acts_as_iphone_controller
+
+And any respond_to block can include iphone as an option, looking for
+.iphone.erb files in the view directory. Passing the argument true, as in
+acts_as_iphone_controller(true) turns on test mode, where all requests are
+treated as iphone regardless of user agent string. This is useful for testing
+in some of the iPhone simulators. You'll need to restart the server for test
+mode changes to take effect.
+
+In your views, several methods from the IuiHelper module are automatically
+imported into your application and are available throughout.
+
+viewport_tag(options = {})
+ Builds the Mobile Safari meta viewport tag, pass the option
+ :device_width => true to specify the options for applications optimized for
+ iPhone. More options to come.
+
+include_iui_files
+ Place in the header of your layout, includes the tags for the iUI CSS and
+ JavaScript files. Also defines the $ function, as in prototype.
+
+button_link_to(name, options, html_options = {})
+ Creates a link with the iUI CSS class of "button"
+
+link_to_replace(name, options, html_options = {})
+ An iUI link which replaces the link tag with the result text. Designed to
+ be used for an anchor inside a list
+
+link_to_external(name, options, html_options = {})
+ An iUI link to an external item, this is an regular HTTP request, as
+ opposed to what iUI normally does, which is an Ajax request
+
+iui_toolbar(initial_caption, search_url = nil)
+ Sets the toolbar -- the caption is the heading. If there is a search_url,
+ then a search button is added to the right side
+
+iui_list(items, options = {})
+ Creates an iPhone style of list. The items are expected to respond to the
+ methods :caption -- the text display for the list, and :url, the url to
+ go to when the item is selected. The :top and :bottom options specify
+ text to be displayed above or below the list items. The :more option
+ specifies an item to go at the end of the list as a link_to_replace. The
+ :as_replace options sends the list items without a surrounding ul tag, to
+ be the response to a link_to_replace.
+
+iui_grouped_list(items, options = {}, &group_by_block)
+ Same as iui_list, but groups each item by their response to the
+ group_by_block
+
+Upcoming
+========
+
+Support for dialogs and panels
+Tests
+Better documentation
+
+
Copyright (c) 2008 Noel Rappin, released under the MIT license
View
22 Rakefile
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the rails_iui plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the rails_iui plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'RailsIui'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
View
3  init.rb
@@ -0,0 +1,3 @@
+require File.dirname(__FILE__) + '/lib/iui_helper.rb'
+require File.dirname(__FILE__) + '/lib/iphone_controller'
+Mime::Type.register_alias "text/html", :iphone
View
1  install.rb
@@ -0,0 +1 @@
+# Install hook code here
View
49 lib/iphone_controller.rb
@@ -0,0 +1,49 @@
+module ActionController
+
+ module IphoneController
+
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
+
+ module ClassMethods
+ def acts_as_iphone_controller(iphone_test_mode = nil)
+ include ActionController::IphoneController::InstanceMethods
+ if iphone_test_mode
+ before_filter :force_iphone_format
+ else
+ before_filter :set_iphone_format
+ end
+ helper_method :is_iphone_request?
+ end
+
+ def iphone_test_mode?
+ @@iphone_test_mode
+ end
+ end
+
+ module InstanceMethods
+
+ def force_iphone_format
+ request.format = :iphone
+ end
+
+ def set_iphone_format
+ if is_iphone_request? or request.format.to_sym == :iphone
+ request.format = if cookies["browser"] == "desktop"
+ then :html
+ else :iphone
+ end
+ end
+ end
+
+ def is_iphone_request?
+ request.user_agent =~ /(Mobile\/.+Safari)/
+ end
+ end
+
+ end
+
+end
+
+ActionController::Base.send(:include, ActionController::IphoneController)
View
87 lib/iui_helper.rb
@@ -0,0 +1,87 @@
+module IuiHelper
+
+ def viewport_tag(options = {})
+ content = ""
+ content += "width = device-width, user-scalable=no" if options[:device_width]
+ content_tag(:meta, :name => "viewport", :content => content)
+ end
+
+ def include_iui_files
+ stylesheet_link_tag('iui') + javascript_include_tag('iui') +
+ javascript_tag("function $(id) { return document.getElementById(id); }")
+ end
+
+ def button_link_to(name, options, html_options = {})
+ html_options[:class] = "button"
+ link_to(name, options, html_options)
+ end
+
+ def link_to_replace(name, options, html_options = {})
+ html_options[:target] = "_replace"
+ link_to(name, options, html_options)
+ end
+
+ def link_to_external(name, options, html_options = {})
+ html_options[:target] = "_self"
+ link_to(name, options, html_options)
+ end
+
+ def link_to_target(target, name, options, html_options = {})
+ if target == :replace
+ link_to_replace(name, options, html_options)
+ elsif target == :self or target == :external
+ link_to_external(name, options, html_options)
+ else
+ link_to(name, options, html_options)
+ end
+ end
+
+ def iui_toolbar(initial_caption, search_url = nil)
+ back_button = button_link_to("", "#", :id => "backButton")
+ header = content_tag(:h1, initial_caption, :id => "header_text")
+ search_link = if search_url
+ then button_link_to("Search", search_url, :id => "searchButton")
+ else ""
+ end
+ content = [back_button, header, search_link].join("\n")
+ content_tag(:div, content, :class => "toolbar")
+ end
+
+ def list_element(item, target=nil)
+ onclick_one = "$('header_text').innerHTML='#{item.caption}'; "
+ onclick_two = "$('backButton').addEventListener('click',
+ function() {$('header_text').innerHTML='Soups OnLine'; }, false);"
+ link = link_to_target(target, item.caption, item.url,
+ :onclick => "#{onclick_one} " + " #{onclick_two}")
+ content_tag(:li, link)
+ end
+
+ def append_options(list_content, options = {})
+ list_content = options[:top] + list_content if options[:top]
+ list_content += list_element(options[:more], :replace) if options[:more]
+ list_content += options[:bottom] if options[:bottom]
+ list_content
+ end
+
+ def iui_list(items, options = {})
+ list_content = items.map {|i| list_element(i)}.join("\n")
+ list_content = append_options(list_content, options)
+ if options[:as_replace]
+ list_content
+ else
+ content_tag(:ul, list_content, :selected => "true")
+ end
+ end
+
+ def iui_grouped_list(items, options = {}, &group_by_block)
+ groups = items.group_by(&group_by_block).sort
+ group_elements = groups.map do |group, members|
+ group = content_tag(:li, group, :class => "group")
+ member_elements = [group] + members.map { |m| list_element(m) }
+ end
+ content_tag(:ul, group_elements.flatten.join("\n"), :selected => "true")
+ end
+
+end
+
+ActionView::Base.send(:include, IuiHelper)
View
9 lib/list_model.rb
@@ -0,0 +1,9 @@
+class ListModel
+ attr_accessor :caption, :url, :obj
+
+ def initialize(obj, caption, url)
+ @obj = obj
+ @caption = caption
+ @url = url
+ end
+end
View
72 tasks/rails_iui_tasks.rake
@@ -0,0 +1,72 @@
+require 'open-uri'
+
+namespace :iui do
+ version = "0.13"
+
+ task :download => :environment do
+ unless File.exist?("#{RAILS_ROOT}/public/javascripts/iui.js")
+ Dir.chdir("#{RAILS_ROOT}/vendor") do
+ url = "http://iui.googlecode.com/files/iui-#{version}.tar.gz"
+ puts "Loading iUI"
+ open("iui-#{version}.tar.gz", 'w').write(open(url).read)
+ system "tar zxvf iui-#{version}.tar.gz"
+ end
+ end
+ end
+
+ task :copy => :environment do
+ Dir.chdir("#{RAILS_ROOT}/vendor/iui") do
+ FileUtils.copy("iui.js", "#{RAILS_ROOT}/public/javascripts")
+ FileUtils.copy("iui.css", "#{RAILS_ROOT}/public/stylesheets")
+ images = Dir.glob('*.png') + Dir.glob('*.gif')
+ images.each do |image|
+ FileUtils.copy(image, "#{RAILS_ROOT}/public/images")
+ end
+ end
+ end
+
+ task :copy_compact => :environment do
+ Dir.chdir("#{RAILS_ROOT}/vendor/iui") do
+ FileUtils.copy("iuix.js", "#{RAILS_ROOT}/public/javascripts")
+ FileUtils.copy("iuix.css", "#{RAILS_ROOT}/public/stylesheets")
+ images = Dir.glob('*.png') + Dir.glob('*.gif')
+ images.each do |image|
+ FileUtils.copy(image, "#{RAILS_ROOT}/public/images")
+ end
+ end
+ end
+
+ task :change_root => :environment do
+ text = ""
+ File.open("#{RAILS_ROOT}/public/stylesheets/iui.css") do |f|
+ text = f.read
+ text.gsub!("url(", "url(/images/")
+ end
+ File.open("#{RAILS_ROOT}/public/stylesheets/iui.css", 'w') do |f|
+ f << text
+ end
+ end
+
+ desc "Installs iUI"
+ task :install => [:environment, :download, :copy, :change_root]
+
+ task :install_compact => [:environment, :download, :copy_compact, :change_root]
+
+ task :clean => :environment do
+ FileUtils.rm_f("#{RAILS_ROOT}/public/javascripts/iui.js")
+ FileUtils.rm_f("#{RAILS_ROOT}/public/stylesheets/iui.css")
+ FileUtils.rm_f("#{RAILS_ROOT}/public/javascripts/iuix.js")
+ FileUtils.rm_f("#{RAILS_ROOT}/public/stylesheets/iuix.css")
+ pngs = %w{backButton blueButton cancel grayButton listArrow listArrowSel listGroup
+ pinstripes selection thumb toggle}
+ pngs.each do |png|
+ FileUtils.rm_f("#{RAILS_ROOT}/public/images/#{png}.png")
+ end
+ FileUtils.rm_f("#{RAILS_ROOT}/public/images/loading.gif")
+ FileUtils.rm_f("#{RAILS_ROOT}/vendor/iui-#{version}.tar.gz")
+ FileUtils.rm_rf("#{RAILS_ROOT}/vendor/iui")
+ end
+
+ task :reinstall => [:environment, :clean, :install]
+ task :reinstall_compact => [:environment, :clean, :install_compact]
+end
View
10 test/iui_helper_test.rb
@@ -0,0 +1,10 @@
+require 'test/unit'
+require "#{File.dirname(__FILE__)}/../lib/iui_helper"
+
+class IuiHelperTest < Test::Unit::TestCase
+ include IuiHelper
+
+ def test_case_name
+ true
+ end
+end
View
1  uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here
Please sign in to comment.
Something went wrong with that request. Please try again.