Removed mile_marker plugin

This commit is contained in:
Alexey Nayden 2011-03-09 22:16:20 +03:00
parent 0686628557
commit f90dea3d72
8 changed files with 0 additions and 280 deletions

View File

@ -1,55 +0,0 @@
= MileMarker Plugin
Author:: Chad Pytel (mailto:cpytel@thoughtbot.com)
Copyright:: Copyright(c) 2007 thoughtbot, inc.
License:: Distributes under the same terms as Ruby
Website:: http://www.thoughtbot.com/projects/mile_marker
A Ruby on Rails plugin for visually setting expectations throughout application development.
Adds a helper for marking page elements with the milestone they are slated to be developed, and makes them unable to be interacted with.
Usage:
Once the plugin has been installed, in your views you can now do:
<div class="person" <%= mile 6 %>>
<div class="name">Your Name<div>
</div>
When viewed in development mode, the person div would be overlaid with a grey box with the words "Milestone 6" in it.
If you happen to not call your milestones, "milestones", or for any other reason want the label to be something different, just supply a string instead:
<div class="person" <%= mile "Next Week" %>>
<div class="name">Your Name<div>
</div>
And that will still result in the marker being labeled with "Next Week" instead.
By default, the milestone markers will be only appear in the Rails development environment. To customize this, add the following to the config file of the other environments you want the markers to appear:
Thoughtbot::MileMarker.enable
If you prefer not to have it on in development, add the following to development.rb
Thoughtbot::MileMarker.disable
Or, if you prefer, add something like the following to environment.rb:
Thoughtbot::MileMarker.environments = %w(development staging production)
You can also change some of the styling options (as of right now, just the z-index and background color) by modifying the options hash:
Thoughtbot::MileMarker.options.update(
:z_index => 100,
:background_color => "purple"
)
== Requirements
The overlay functionality requires javascript, and uses the prototype library. So, any page that is using this functionality must also include prototype.
== Todo
* Rake task to find and print out (with line numbers) all of the milestone markers

View File

@ -1,22 +0,0 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
desc 'Test the mile_marker plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
desc 'Generate documentation for the mile_marker plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Mile Marker'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end

View File

@ -1,4 +0,0 @@
require 'mile_marker'
ActionView::Base.send :include, Thoughtbot::MileMarkerHelper
ActionController::Base.send :include, Thoughtbot::MileMarkerHelper
ActionController::Base.send :after_filter, :add_initialize_mile_marker

View File

@ -1 +0,0 @@
# Install hook code here

View File

@ -1,100 +0,0 @@
module Thoughtbot
module MileMarkerHelper
def mile(detail="")
return unless MileMarker.enabled?
"mile=\"" + (detail.is_a?(Fixnum) ? "Milestone " : "") + "#{detail}\""
end
def initialize_mile_marker(request = nil)
return unless MileMarker.enabled?
MileMarker.initialize_mile_marker()
end
def add_initialize_mile_marker()
init_code = initialize_mile_marker()
return if init_code.nil? || init_code.empty?
response.body.gsub! /<\/(head)>/i, init_code + '</\1>' if response.body.respond_to?(:gsub!)
end
end
class MileMarker
# The environments in which to enable the Mile Marker functionality to run. Defaults
# to 'development' only.
@@environments = ['development']
class << self
attr_accessor :environments
end
def self.options
@options ||= {
:z_index => 1000,
:background_color => "#000"
}
end
# Return true if the Mile Marker functionality is enabled for the current environment
def self.enabled?
environments.include?(ENV['RAILS_ENV'])
end
def self.enable
environments.push ENV['RAILS_ENV']
end
def self.disable
environments.delete ENV['RAILS_ENV']
end
def self.initialize_mile_marker()
%Q~
<script type="text/javascript">
//<![CDATA[
function over(element) {
element.setStyle({opacity: 1.0});
}
function init_miles() {
$$('*[mile]').each(function(block, index) {
html = '<div id="mile_'+index+'" style="display: none; z-index: #{options[:z_index]}; position: absolute; background-color: #{options[:background_color]}; opacity: 0.4; filter: alpha(opacity=40); color: #eee; font-family: Lucida Sans, Helvetica; font-size: 16px; font-weight: bold; white-space: nowrap; overflow: hidden;"><p style="padding: 3px 5px; background-color: #{options[:background_color]}; opacity: 1.0; filter: alpha(opacity=100); display: inline; color: #f3f3f3;">'+block.getAttribute('mile')+'</p></div>'
new Insertion.Before($(block), html);
Position.clone($(block), $('mile_'+index));
if($('mile_'+index).getHeight() <= 25) { $('mile_'+index).setStyle({fontSize: '10px'}); }
$('mile_'+index).observe("mouseover", function(event) {
element = Event.element(event);
if(element.immediateDescendants()[0])
{
element.setStyle({opacity: 0.75});
if(element.style.filters) element.style.filters.alpha.opacity=75;
}
else
{
element.up().setStyle({opacity: 0.75});
if(element.up().style.filters) element.up().style.filters.alpha.opacity=75;
}
});
$('mile_'+index).observe("mouseout", function(event) {
element = Event.element(event);
if(element.immediateDescendants()[0])
{
element.setStyle({opacity: 0.4});
if(element.style.filters) element.style.filters.alpha.opacity=40;
}
else
{
element.up().setStyle({opacity: 0.4});
if(element.up().style.filters) element.up().style.filters.alpha.opacity=40;
}
});
$('mile_'+index).toggle();
});
}
if(Event.observe) {
Event.observe(window, 'load', init_miles, false);
} else {
if(window.addEvent) window.addEvent('domready', init_miles);
}
//]]>
</script>
~
end
end
end

View File

@ -1,82 +0,0 @@
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
class MileMarkerTest < Test::Unit::TestCase
include Thoughtbot::MileMarkerHelper
def test_mile_helper_should_return_nothing_if_no_enabled
Thoughtbot::MileMarker.environments = ['development']
ENV['RAILS_ENV']="test_environment"
output = mile("Milestone 1")
assert_nil output
end
def test_mile_helper_should_include_detail_when_supplied_detail
Thoughtbot::MileMarker.environments = ['development']
ENV['RAILS_ENV']="development"
output = mile("Milestone 1")
assert_equal "mile=\"Milestone 1\"", output
end
def test_mile_helper_should_include_add_milestone_when_supplied_integer
Thoughtbot::MileMarker.environments = ['development']
ENV['RAILS_ENV']="development"
output = mile(1)
assert_equal "mile=\"Milestone 1\"", output
end
def test_mile_helper_should_include_no_detail_when_supplied_no_detail
Thoughtbot::MileMarker.environments = ['development']
ENV['RAILS_ENV']="development"
output = mile
assert_equal "mile=\"\"", output
end
def test_calling_enabled_should_add_current_environment_to_environments
Thoughtbot::MileMarker.environments = []
ENV['RAILS_ENV']="test_environment"
Thoughtbot::MileMarker.enable
assert Thoughtbot::MileMarker.environments.include?(ENV['RAILS_ENV'])
end
def test_calling_disabled_should_remove_current_environment_from_environments
Thoughtbot::MileMarker.environments = []
ENV['RAILS_ENV']="test_environment"
Thoughtbot::MileMarker.enable
assert Thoughtbot::MileMarker.environments.include?(ENV['RAILS_ENV'])
Thoughtbot::MileMarker.disable
assert !Thoughtbot::MileMarker.environments.include?(ENV['RAILS_ENV'])
end
def test_initialize_mile_should_return_nothing_if_not_enabled
ENV['RAILS_ENV']="test_environment"
output = initialize_mile_marker
assert_nil output
end
def test_initialize_mile_should_return_javascript_if_enabled
Thoughtbot::MileMarker.environments = ['development']
ENV['RAILS_ENV']="development"
output = initialize_mile_marker
assert_match /function init_miles/, output
end
def test_javascript_should_be_added_to_head_if_enabled
Thoughtbot::MileMarker.environments = ['development']
ENV['RAILS_ENV']="development"
response.body = "<head></head>"
add_initialize_mile_marker
assert_match /script/, response.body
end
def test_z_index_and_other_options_in_css_set_as_specified_in_options
Thoughtbot::MileMarker.environments = ['development']
Thoughtbot::MileMarker.options[:z_index] = "1234"
Thoughtbot::MileMarker.options[:background_color] = "purple"
ENV['RAILS_ENV']="development"
response.body = "<head></head>"
add_initialize_mile_marker
assert_match /script/, response.body
assert_match /z-index: 1234/, response.body
assert_match /background-color: purple/, response.body
end
end

View File

@ -1,15 +0,0 @@
$:.unshift(File.dirname(__FILE__) + '/../lib')
ENV['RAILS_ENV'] = 'test'
require 'test/unit'
require File.join(File.dirname(File.dirname(__FILE__)), "lib", "mile_marker")
require 'ostruct'
module MockResponse
def response
@test_response ||= OpenStruct.new({:body => ""})
end
end
Test::Unit::TestCase.send :include, MockResponse
Thoughtbot::MileMarkerHelper.send :include, MockResponse

View File

@ -1 +0,0 @@
# Uninstall hook code here