Module: Phlex::Rails::HelperMacros

Included in:
Phlex::Rails::Helpers::ActionCableMetaTag, Phlex::Rails::Helpers::ActionName, Phlex::Rails::Helpers::AssetPath, Phlex::Rails::Helpers::AssetURL, Phlex::Rails::Helpers::AudioPath, Phlex::Rails::Helpers::AudioTag, Phlex::Rails::Helpers::AudioURL, Phlex::Rails::Helpers::AutoDiscoveryLinkTag, Phlex::Rails::Helpers::BuildTagValues, Phlex::Rails::Helpers::ButtonTag, Phlex::Rails::Helpers::ButtonTo, Phlex::Rails::Helpers::CSPMetaTag, Phlex::Rails::Helpers::CSRFMetaTags, Phlex::Rails::Helpers::CheckBox, Phlex::Rails::Helpers::CheckBoxTag, Phlex::Rails::Helpers::ClassNames, Phlex::Rails::Helpers::CollectionCheckBoxes, Phlex::Rails::Helpers::CollectionRadioButtons, Phlex::Rails::Helpers::CollectionSelect, Phlex::Rails::Helpers::ColorField, Phlex::Rails::Helpers::ColorFieldTag, Phlex::Rails::Helpers::ComputeAssetExtname, Phlex::Rails::Helpers::ComputeAssetHost, Phlex::Rails::Helpers::ComputeAssetPath, Phlex::Rails::Helpers::ContentFor, Phlex::Rails::Helpers::ContentTag, Phlex::Rails::Helpers::ControllerName, Phlex::Rails::Helpers::ControllerPath, Phlex::Rails::Helpers::CurrentCycle, Phlex::Rails::Helpers::CurrentPage, Phlex::Rails::Helpers::Cycle, Phlex::Rails::Helpers::DOMClass, Phlex::Rails::Helpers::DOMID, Phlex::Rails::Helpers::DateField, Phlex::Rails::Helpers::DateFieldTag, Phlex::Rails::Helpers::DateSelect, Phlex::Rails::Helpers::DatetimeField, Phlex::Rails::Helpers::DatetimeFieldTag, Phlex::Rails::Helpers::DatetimeLocalField, Phlex::Rails::Helpers::DatetimeLocalFieldTag, Phlex::Rails::Helpers::DatetimeSelect, Phlex::Rails::Helpers::Debug, Phlex::Rails::Helpers::DefaultURLOptions, Phlex::Rails::Helpers::DistanceOfTimeInWords, Phlex::Rails::Helpers::DistanceOfTimeInWordsToNow, Phlex::Rails::Helpers::EmailField, Phlex::Rails::Helpers::EmailFieldTag, Phlex::Rails::Helpers::ErrorMessage, Phlex::Rails::Helpers::ErrorWrapping, Phlex::Rails::Helpers::EscapeOnce, Phlex::Rails::Helpers::Excerpt, Phlex::Rails::Helpers::FaviconLinkTag, Phlex::Rails::Helpers::FieldID, Phlex::Rails::Helpers::FieldName, Phlex::Rails::Helpers::FieldSetTag, Phlex::Rails::Helpers::Fields, Phlex::Rails::Helpers::FieldsFor, Phlex::Rails::Helpers::FileField, Phlex::Rails::Helpers::FileFieldTag, Phlex::Rails::Helpers::Flash, Phlex::Rails::Helpers::FontPath, Phlex::Rails::Helpers::FontURL, Phlex::Rails::Helpers::FormFor, Phlex::Rails::Helpers::FormTag, Phlex::Rails::Helpers::FormWith, Phlex::Rails::Helpers::GroupedCollectionSelect, Phlex::Rails::Helpers::GroupedOptionsForSelect, Phlex::Rails::Helpers::HiddenField, Phlex::Rails::Helpers::HiddenFieldTag, Phlex::Rails::Helpers::Highlight, Phlex::Rails::Helpers::ImagePath, Phlex::Rails::Helpers::ImageSubmitTag, Phlex::Rails::Helpers::ImageTag, Phlex::Rails::Helpers::ImageURL, Phlex::Rails::Helpers::JavascriptImportModuleTag, Phlex::Rails::Helpers::JavascriptImportmapTags, Phlex::Rails::Helpers::JavascriptIncludeTag, Phlex::Rails::Helpers::JavascriptPath, Phlex::Rails::Helpers::JavascriptTag, Phlex::Rails::Helpers::JavascriptURL, Phlex::Rails::Helpers::L, Phlex::Rails::Helpers::Label, Phlex::Rails::Helpers::LabelTag, Phlex::Rails::Helpers::LinkTo, Phlex::Rails::Helpers::LinkToIf, Phlex::Rails::Helpers::LinkToUnless, Phlex::Rails::Helpers::LinkToUnlessCurrent, Phlex::Rails::Helpers::Localize, Phlex::Rails::Helpers::MailTo, Phlex::Rails::Helpers::MonthField, Phlex::Rails::Helpers::MonthFieldTag, Phlex::Rails::Helpers::NumberField, Phlex::Rails::Helpers::NumberFieldTag, Phlex::Rails::Helpers::NumberToCurrency, Phlex::Rails::Helpers::NumberToHuman, Phlex::Rails::Helpers::NumberToHumanSize, Phlex::Rails::Helpers::NumberToPercentage, Phlex::Rails::Helpers::NumberToPhone, Phlex::Rails::Helpers::NumberWithDelimiter, Phlex::Rails::Helpers::NumberWithPrecision, Phlex::Rails::Helpers::Object, Phlex::Rails::Helpers::OptionGroupsFromCollectionForSelect, Phlex::Rails::Helpers::OptionsForSelect, Phlex::Rails::Helpers::OptionsFromCollectionForSelect, Phlex::Rails::Helpers::PasswordField, Phlex::Rails::Helpers::PasswordFieldTag, Phlex::Rails::Helpers::PathToAsset, Phlex::Rails::Helpers::PathToAudio, Phlex::Rails::Helpers::PathToFont, Phlex::Rails::Helpers::PathToImage, Phlex::Rails::Helpers::PathToJavascript, Phlex::Rails::Helpers::PathToStylesheet, Phlex::Rails::Helpers::PathToVideo, Phlex::Rails::Helpers::PhoneField, Phlex::Rails::Helpers::PhoneFieldTag, Phlex::Rails::Helpers::PhoneTo, Phlex::Rails::Helpers::Pluralize, Phlex::Rails::Helpers::PreloadLinkTag, Phlex::Rails::Helpers::Provide, Phlex::Rails::Helpers::PublicComputeAssetPath, Phlex::Rails::Helpers::RadioButton, Phlex::Rails::Helpers::RadioButtonTag, Phlex::Rails::Helpers::RangeField, Phlex::Rails::Helpers::RangeFieldTag, Phlex::Rails::Helpers::Request, Phlex::Rails::Helpers::ResetCycle, Phlex::Rails::Helpers::RichTextArea, Phlex::Rails::Helpers::SMSTo, Phlex::Rails::Helpers::Sanitize, Phlex::Rails::Helpers::SanitizeCSS, Phlex::Rails::Helpers::SearchField, Phlex::Rails::Helpers::SearchFieldTag, Phlex::Rails::Helpers::Select, Phlex::Rails::Helpers::SelectDate, Phlex::Rails::Helpers::SelectDatetime, Phlex::Rails::Helpers::SelectDay, Phlex::Rails::Helpers::SelectHour, Phlex::Rails::Helpers::SelectMinute, Phlex::Rails::Helpers::SelectMonth, Phlex::Rails::Helpers::SelectSecond, Phlex::Rails::Helpers::SelectTag, Phlex::Rails::Helpers::SelectTime, Phlex::Rails::Helpers::SelectYear, Phlex::Rails::Helpers::SimpleFormat, Phlex::Rails::Helpers::StripLinks, Phlex::Rails::Helpers::StripTags, Phlex::Rails::Helpers::StylesheetLinkTag, Phlex::Rails::Helpers::StylesheetPath, Phlex::Rails::Helpers::StylesheetURL, Phlex::Rails::Helpers::SubmitTag, Phlex::Rails::Helpers::TelephoneField, Phlex::Rails::Helpers::TelephoneFieldTag, Phlex::Rails::Helpers::TextArea, Phlex::Rails::Helpers::TextAreaTag, Phlex::Rails::Helpers::TextField, Phlex::Rails::Helpers::TextFieldTag, Phlex::Rails::Helpers::TimeAgoInWords, Phlex::Rails::Helpers::TimeField, Phlex::Rails::Helpers::TimeFieldTag, Phlex::Rails::Helpers::TimeSelect, Phlex::Rails::Helpers::TimeTag, Phlex::Rails::Helpers::TimeZoneOptionsForSelect, Phlex::Rails::Helpers::TimeZoneSelect, Phlex::Rails::Helpers::TokenList, Phlex::Rails::Helpers::Truncate, Phlex::Rails::Helpers::TurboFrameTag, Phlex::Rails::Helpers::TurboIncludeTags, Phlex::Rails::Helpers::TurboRefreshMethodTag, Phlex::Rails::Helpers::TurboRefreshScrollTag, Phlex::Rails::Helpers::TurboRefreshesWith, Phlex::Rails::Helpers::TurboStream, Phlex::Rails::Helpers::TurboStreamFrom, Phlex::Rails::Helpers::URLField, Phlex::Rails::Helpers::URLFieldTag, Phlex::Rails::Helpers::URLFor, Phlex::Rails::Helpers::URLOptions, Phlex::Rails::Helpers::URLToAsset, Phlex::Rails::Helpers::URLToAudio, Phlex::Rails::Helpers::URLToFont, Phlex::Rails::Helpers::URLToImage, Phlex::Rails::Helpers::URLToJavascript, Phlex::Rails::Helpers::URLToStylesheet, Phlex::Rails::Helpers::URLToVideo, Phlex::Rails::Helpers::UTF8EnforcerTag, Phlex::Rails::Helpers::VideoPath, Phlex::Rails::Helpers::VideoTag, Phlex::Rails::Helpers::VideoURL, Phlex::Rails::Helpers::WeekField, Phlex::Rails::Helpers::WeekFieldTag, Phlex::Rails::Helpers::WeekdayOptionsForSelect, Phlex::Rails::Helpers::WeekdaySelect, Phlex::Rails::Helpers::WithOutputBuffer, Phlex::Rails::Helpers::WordWrap
Defined in:
lib/phlex/rails/helper_macros.rb

Instance Method Summary collapse

Instance Method Details

#register_output_helper(method_name) ⇒ Object

Register a Rails helper that returns safe HTML to be pushed to the output buffer.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/phlex/rails/helper_macros.rb', line 5

def register_output_helper(method_name)
	class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
		# frozen_string_literal: true

		def #{method_name}(*args, **kwargs, &block)
 			context = @_context
 			return if context.fragments && !context.in_target_fragment

			output = if block
				helpers.#{method_name}(*args, **kwargs) { capture(&block) }
			else
				helpers.#{method_name}(*args, **kwargs)
			end

			case output
			when ActiveSupport::SafeBuffer
				@_context.target << output
			end

			nil
		end
	RUBY
end

#register_value_helper(method_name) ⇒ Object

Register a Rails helper that returns a value that shouldn’t be pushed to the output buffer.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/phlex/rails/helper_macros.rb', line 30

def register_value_helper(method_name)
	class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
		# frozen_string_literal: true

		def #{method_name}(*args, **kwargs, &block)
			if block
				helpers.#{method_name}(*args, **kwargs) { capture(&block) }
			else
				helpers.#{method_name}(*args, **kwargs)
			end
		end
	RUBY
end