idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
5,000
def write y , x , s , opts = { } return if x >= @width || y >= @height @w . attrset Colormap . color_for ( opts [ :color ] || :none , opts [ :highlight ] ) s ||= "" maxl = @width - x @w . mvaddstr y , x , " " * maxl unless opts [ :no_fill ] @w . mvaddstr y , x , s . slice_by_display_length ( maxl ) end
s nil means a blank line!
5,001
def roll_buffers bufs = rollable_buffers bufs . last . force_to_top = false raise_to_front bufs . first end
we reset force_to_top when rolling buffers . this is so that the human can actually still move buffers around while still programmatically being able to pop stuff up in the middle of drawing a window without worrying about covering it up .
5,002
def ask_for_labels domain , question , default_labels , forbidden_labels = [ ] default_labels = default_labels - forbidden_labels - LabelManager :: RESERVED_LABELS default = default_labels . to_a . join ( " " ) default += " " unless default . empty? applyable_labels = ( LabelManager . user_defined_labels - forbidden_la...
returns an array of labels
5,003
def ask domain , question , default = nil , & block raise "impossible!" if @asking raise "Question too long" if Ncurses . cols <= question . length @asking = true @textfields [ domain ] ||= TextField . new tf = @textfields [ domain ] completion_buf = nil status , title = get_status_and_title @focus_buf Ncurses . sync d...
for simplicitly we always place the question at the very bottom of the screen
5,004
def drop_contact person aalias = @p2a [ person ] @p2a . delete person @e2p . delete person . email @a2p . delete aalias if aalias end
this may not actually be called anywhere since we still keep contacts around without aliases to override any fullname changes .
5,005
def regen_text @text = [ ] @chunk_lines = [ ] @message_lines = [ ] @person_lines = [ ] prevm = nil @thread . each do | m , depth , parent | unless m . is_a? Message @text += chunk_to_lines m , nil , @text . length , depth , parent next end l = @layout [ m ] next unless @layout [ m ] . state text = chunk_to_lines m , l ...
here we generate the actual content lines . we accumulate everything into
5,006
def num_results_for query = { } xapian_query = build_xapian_query query matchset = run_query xapian_query , 0 , 0 , 100 matchset . matches_estimated end
Return the number of matches for query in the index
5,007
def build_message id entry = synchronize { get_entry id } return unless entry locations = entry [ :locations ] . map do | source_id , source_info | source = SourceManager [ source_id ] raise "invalid source #{source_id}" unless source Location . new source , source_info end m = Message . new :locations => locations , :...
Load message with the given message - id from the index
5,008
def load_contacts email_addresses , opts = { } contacts = Set . new num = opts [ :num ] || 20 each_id_by_date :participants => email_addresses do | id , b | break if contacts . size >= num m = b . call ( [ m . from ] + m . to + m . cc + m . bcc ) . compact . each { | p | contacts << [ p . name , p . email ] } end conta...
Given an array of email addresses return an array of Person objects that have sent mail to or received mail from any of the given addresses .
5,009
def index_message_static m , doc , entry person_termer = lambda do | d | lambda do | p | doc . index_text p . name , PREFIX [ "#{d}_name" ] [ :prefix ] if p . name doc . index_text p . email , PREFIX [ 'email_text' ] [ :prefix ] doc . add_term mkterm ( :email , d , p . email ) end end person_termer [ :from ] [ m . from...
Index content that can t be changed by the user
5,010
def mkterm type , * args case type when :label PREFIX [ 'label' ] [ :prefix ] + args [ 0 ] . to_s . downcase when :type PREFIX [ 'type' ] [ :prefix ] + args [ 0 ] . to_s . downcase when :date PREFIX [ 'date' ] [ :prefix ] + args [ 0 ] . getutc . strftime ( "%Y%m%d%H%M%S" ) when :email case args [ 0 ] when :from then PR...
Construct a Xapian term
5,011
def link p , c , overwrite = false if p == c || p . descendant_of? ( c ) || c . descendant_of? ( p ) return end return unless c . parent . nil? || overwrite remove_container c p . children << c c . parent = p prune_thread_of c end
link two containers
5,012
def load_thread_for_message m , opts = { } good = @index . each_message_in_thread_for m , opts do | mid , builder | next if contains_id? mid add_message builder . call end add_message m if good end
loads in all messages needed to thread m may do nothing if m s thread is killed
5,013
def add_thread t raise "duplicate" if @threads . values . member? t t . each { | m , * o | add_message m } end
merges in a pre - loaded thread
5,014
def join_threads threads return if threads . size < 2 containers = threads . map do | t | c = @messages . member? ( t . first . id ) ? @messages [ t . first . id ] : nil raise "not in threadset: #{t.first.id}" unless c && c . message c end parent = containers . find { | c | ! c . is_reply? } parent ||= @messages [ "joi...
merges two threads together . both must be members of this threadset . does its best heuristically to determine which is the parent .
5,015
def add_message message el = @messages [ message . id ] return if el . message el . message = message oldroot = el . root ( message . refs + [ el . id ] ) . inject ( nil ) do | prev , ref_id | ref = @messages [ ref_id ] link prev , ref if prev ref end message . replytos . each do | ref_id | ref = @messages [ ref_id ] l...
the heart of the threading code
5,016
def load_from_source! @chunks ||= begin rmsg = location . parsed_message parse_header rmsg . header message_to_chunks rmsg rescue SourceError , SocketError , RMail :: EncodingUnsupportedError => e warn_with_location "problem reading message #{id}" debug "could not load message: #{location.inspect}, exception: #{e.inspe...
this is called when the message body needs to actually be loaded .
5,017
def indexable_content load_from_source! [ from && from . indexable_content , to . map { | p | p . indexable_content } , cc . map { | p | p . indexable_content } , bcc . map { | p | p . indexable_content } , indexable_chunks . map { | c | c . lines . map { | l | l . fix_encoding! } } , indexable_subject , ] . flatten . ...
returns all the content from a message that will be indexed
5,018
def multipart_signed_to_chunks m if m . body . size != 2 warn_with_location "multipart/signed with #{m.body.size} parts (expecting 2)" return end payload , signature = m . body if signature . multipart? warn_with_location "multipart/signed with payload multipart #{payload.multipart?} and signature multipart #{signature...
here s where we handle decoding mime attachments . unfortunately but unsurprisingly the world of mime attachments is a bit of a mess . as an empiricist i m basing the following behavior on observed mail rather than on interpretations of rfcs so probably this will have to be tweaked .
5,019
def string_for l if RESERVED_LABELS . include? l l . to_s . capitalize else l . to_s end end
reverse the label - > string mapping for convenience!
5,020
def search_goto_pos line , leftcol , rightcol search_goto_line line if rightcol > self . rightcol jump_to_col [ rightcol - buffer . content_width + 1 , 0 ] . max end end
subclasses can override these three!
5,021
def jump_to_line l l = l . clamp 0 , lines - 1 return if @topline == l @topline = l @botline = [ l + buffer . content_height , lines ] . min buffer . mark_dirty end
set top line to l
5,022
def page_down if topline > lines - buffer . content_height set_cursor_pos ( lines - 1 ) elsif topline == lines - buffer . content_height call_load_more_callbacks buffer . content_height super else relpos = @curpos - topline super set_cursor_pos [ topline + relpos , lines - 1 ] . min end end
more complicated than one might think . three behaviors .
5,023
def get_cursed_value return nil unless @field x = Ncurses . curx form_driver_key Ncurses :: Form :: REQ_VALIDATION v = @field . field_buffer ( 0 ) . gsub ( / \s \s / , "" ) if x - @question . length - v . length <= 0 v else v + ( " " * ( x - @question . length - v . length ) ) end v . force_encoding ( $encoding ) . fix...
ncurses inanity wrapper
5,024
def trigger_success ( data = nil ) event . success = true event . data = data event . trigger end
Trigger the success callback function attached to the client event that triggered this action . The object passed to this method will be passed as an argument to the callback function on the client .
5,025
def trigger_failure ( data = nil ) event . success = false event . data = data event . trigger end
Trigger the failure callback function attached to the client event that triggered this action . The object passed to this method will be passed as an argument to the callback function on the client .
5,026
def send_message ( event_name , message , options = { } ) options . merge! :connection => connection , :data => message event = Event . new ( event_name , options ) @_dispatcher . send_message event if @_dispatcher . respond_to? ( :send_message ) end
Sends a message to the client that initiated the current event being executed . Messages are serialized as JSON into a two element Array where the first element is the event and the second element is the message that was passed typically a Hash .
5,027
def reload! ( controller ) return controller unless defined? ( Rails ) and ! Rails . configuration . cache_classes unless controller . name == "WebsocketRails::InternalController" class_name = controller . name filename = class_name . underscore load "#{filename}.rb" return class_name . constantize end return controlle...
Reloads the controller class to pick up code changes while in the development environment .
5,028
def call ( env ) request = ActionDispatch :: Request . new ( env ) if request . post? response = parse_incoming_event ( request . params ) else response = open_connection ( request ) end response rescue InvalidConnectionError BadRequestResponse end
Primary entry point for the Rack application
5,029
def legacy_page_redirect_url page = last_legacy_url . page return unless page alchemy . show_page_path ( locale : prefix_locale? ? page . language_code : nil , urlname : page . urlname ) end
Use the bare minimum to redirect to legacy page
5,030
def update_contents ( contents_attributes ) return true if contents_attributes . nil? contents . each do | content | content_hash = contents_attributes [ content . id . to_s ] || next content . update_essence ( content_hash ) || errors . add ( :base , :essence_validation_failed ) end errors . blank? end
Updates all related contents by calling + update_essence + on each of them .
5,031
def copy_contents_to ( element ) contents . map do | content | Content . copy ( content , element_id : element . id ) end end
Copy current content s contents to given target element
5,032
def content_definition_for ( content_name ) if content_definitions . blank? log_warning "Element #{name} is missing the content definition for #{content_name}" nil else content_definitions . detect { | d | d [ 'name' ] == content_name } end end
Returns the definition for given content_name
5,033
def richtext_contents_ids ids = contents . select ( & :has_tinymce? ) . collect ( & :id ) expanded_nested_elements = nested_elements . expanded if expanded_nested_elements . present? ids += expanded_nested_elements . collect ( & :richtext_contents_ids ) end ids . flatten end
Returns an array of all EssenceRichtext contents ids from elements
5,034
def create_contents definition . fetch ( 'contents' , [ ] ) . each do | attributes | Content . create ( attributes . merge ( element : self ) ) end end
creates the contents for this element as described in the elements . yml
5,035
def available_element_definitions ( only_element_named = nil ) @_element_definitions ||= if only_element_named definition = Element . definition_by_name ( only_element_named ) element_definitions_by_name ( definition [ 'nestable_elements' ] ) else element_definitions end return [ ] if @_element_definitions . blank? @_e...
All available element definitions that can actually be placed on current page .
5,036
def available_elements_within_current_scope ( parent ) @_available_elements = if parent parents_unique_nested_elements = parent . nested_elements . where ( unique : true ) . pluck ( :name ) available_element_definitions ( parent . name ) . reject do | e | parents_unique_nested_elements . include? e [ 'name' ] end else ...
Available element definitions excluding nested unique elements .
5,037
def descendent_element_definitions definitions = element_definitions_by_name ( element_definition_names ) definitions . select { | d | d . key? ( 'nestable_elements' ) } . each do | d | definitions += element_definitions_by_name ( d [ 'nestable_elements' ] ) end definitions . uniq { | d | d [ 'name' ] } end
All element definitions defined for page s page layout including nestable element definitions
5,038
def generate_elements elements_already_on_page = elements_including_fixed . pluck ( :name ) definition . fetch ( 'autogenerate' , [ ] ) . each do | element_name | next if elements_already_on_page . include? ( element_name ) Element . create ( page : self , name : element_name ) end end
Looks in the page_layout descripion if there are elements to autogenerate .
5,039
def delete_outnumbered_element_definitions! @_element_definitions . delete_if do | element | outnumbered = @_existing_element_names . select { | name | name == element [ 'name' ] } element [ 'amount' ] && outnumbered . count >= element [ 'amount' ] . to_i end end
Deletes limited and outnumbered definitions from
5,040
def on_page_layout ( page_layouts , callback = nil , & block ) callback = block || callback [ page_layouts ] . flatten . each do | page_layout | if callback OnPageLayout . register_callback ( page_layout , callback ) else raise ArgumentError , "You need to either pass a block or method name as a callback for `on_page_l...
Define a page layout callback
5,041
def serialize { name : name , value : serialized_ingredient , link : essence . try ( :link ) } . delete_if { | _k , v | v . blank? } end
Serialized object representation for json api
5,042
def update_essence ( params = { } ) raise EssenceMissingError if essence . nil? if essence . update ( params ) return true else errors . add ( :essence , :validation_failed ) return false end end
Updates the essence .
5,043
def element_view_for ( element , options = { } ) options = { tag : :div , id : element_dom_id ( element ) , class : element . name , tags_formatter : -> ( tags ) { tags . join ( " " ) } } . merge ( options ) output = capture do yield ElementViewHelper . new ( self , element : element ) if block_given? end if tag = opti...
Block - level helper for element views . Constructs a DOM element wrapping your content element and provides a block helper object you can use for concise access to Alchemy s various helpers .
5,044
def url ( options = { } ) image = image_file raise MissingImageFileError , "Missing image file for #{inspect}" if image . nil? image = processed_image ( image , options ) image = encoded_image ( image , options ) image . url ( options . except ( * TRANSFORMATION_OPTIONS ) . merge ( name : name ) ) rescue MissingImageFi...
Returns a path to picture for use inside a image_tag helper .
5,045
def processed_image ( image , options = { } ) size = options [ :size ] upsample = ! ! options [ :upsample ] return image unless size . present? && has_convertible_format? if options [ :crop ] crop ( size , options [ :crop_from ] , options [ :crop_size ] , upsample ) else resize ( size , upsample ) end end
Returns the processed image dependent of size and cropping parameters
5,046
def encoded_image ( image , options = { } ) target_format = options [ :format ] || default_render_format unless target_format . in? ( Alchemy :: Picture . allowed_filetypes ) raise WrongImageFormatError . new ( self , target_format ) end options = { flatten : target_format != 'gif' && image_file_format == 'gif' } . mer...
Returns the encoded image
5,047
def render_attribute ( resource , attribute , options = { } ) attribute_value = resource . send ( attribute [ :name ] ) if attribute [ :relation ] record = resource . send ( attribute [ :relation ] [ :name ] ) value = record . present? ? record . send ( attribute [ :relation ] [ :attr_method ] ) : Alchemy . t ( :not_fo...
Returns the value from resource attribute
5,048
def resource_attribute_field_options ( attribute ) options = { hint : resource_handler . help_text_for ( attribute ) } input_type = attribute [ :type ] . to_s case input_type when 'boolean' options when 'date' , 'time' , 'datetime' date = resource_instance_variable . send ( attribute [ :name ] ) || Time . current optio...
Returns a options hash for simple_form input fields .
5,049
def render_resources render partial : resource_name , collection : resources_instance_variable rescue ActionView :: MissingTemplate render partial : 'resource' , collection : resources_instance_variable end
Renders the row for a resource record in the resources table .
5,050
def searchable_attribute_names if model . respond_to? ( :searchable_alchemy_resource_attributes ) model . searchable_alchemy_resource_attributes else attributes . select { | a | searchable_attribute? ( a ) } . concat ( searchable_relation_attributes ( attributes ) ) . collect { | h | h [ :name ] } end end
Returns all attribute names that are searchable in the admin interface
5,051
def help_text_for ( attribute ) :: I18n . translate! ( attribute [ :name ] , scope : [ :alchemy , :resource_help_texts , resource_name ] ) rescue :: I18n :: MissingTranslationData false end
Returns a help text for resource s form
5,052
def map_relations self . resource_relations = { } model . alchemy_resource_relations . each do | name , options | name = name . to_s . gsub ( / / , '' ) association = association_from_relation_name ( name ) foreign_key = association . options [ :foreign_key ] || "#{association.name}_id" . to_sym resource_relations [ fo...
Expands the resource_relations hash with matching activerecord associations data .
5,053
def store_model_associations self . model_associations = model . reflect_on_all_associations . delete_if { | a | DEFAULT_SKIPPED_ASSOCIATIONS . include? ( a . name . to_s ) } end
Stores all activerecord associations in model_associations attribute
5,054
def display_todos return if todos . empty? log "\n+---------+" , :message log "| 📝 TODO |", : m ssage log "+---------+\n" , :message puts "\nWe did most of the work for you, but there are still some things left for you to do." todos . each_with_index do | todo , i | title = "\n#{i + 1}. #{todo[0]}" log title , :messag...
Prints out all the todos
5,055
def log ( message , type = nil ) unless Alchemy :: Shell . silenced? case type when :skip puts "#{color(:yellow)}== Skipping! #{message}#{color(:clear)}" when :error puts "#{color(:red)}!! ERROR: #{message}#{color(:clear)}" when :message puts "#{color(:clear)}#{message}" else puts "#{color(:green)}== #{message}#{color(...
Prints out the given log message with the color due to its type
5,056
def color ( name ) color_const = name . to_s . upcase if Thor :: Shell :: Color . const_defined? ( color_const ) "Thor::Shell::Color::#{color_const}" . constantize else "" end end
Gives the color string using Thor Used for colorizing the message on the shell
5,057
def picture_url_options return { } if picture . nil? { format : picture . default_render_format , crop_from : crop_from . presence , crop_size : crop_size . presence } . with_indifferent_access end
Picture rendering options
5,058
def thumbnail_url ( options = { } ) return if picture . nil? crop = crop_values_present? || content . settings_value ( :crop , options ) size = render_size || content . settings_value ( :size , options ) options = { size : thumbnail_size ( size , crop ) , crop : ! ! crop , crop_from : crop_from . presence , crop_size :...
Returns an url for the thumbnail representation of the assigned picture
5,059
def cropping_mask return if crop_from . blank? || crop_size . blank? crop_from = point_from_string ( read_attribute ( :crop_from ) ) crop_size = sizes_from_string ( read_attribute ( :crop_size ) ) point_and_mask_to_points ( crop_from , crop_size ) end
A Hash of coordinates suitable for the graphical image cropper .
5,060
def allow_image_cropping? ( options = { } ) content && content . settings_value ( :crop , options ) && picture && picture . can_be_cropped_to ( content . settings_value ( :size , options ) , content . settings_value ( :upsample , options ) ) end
Show image cropping link for content and options?
5,061
def hint hint = definition [ 'hint' ] if hint == true Alchemy . t ( name , scope : hint_translation_scope ) else hint end end
Returns a hint
5,062
def default_mask ( mask_arg ) mask = mask_arg . dup mask [ :width ] = image_file_width if mask [ :width ] . zero? mask [ :height ] = image_file_height if mask [ :height ] . zero? crop_size = size_when_fitting ( { width : image_file_width , height : image_file_height } , mask ) top_left = get_top_left_crop_corner ( crop...
Returns the default centered image mask for a given size . If the mask is bigger than the image the mask is scaled down so the largest possible part of the image is visible .
5,063
def thumbnail_size ( size_string = "0x0" , crop = false ) size = sizes_from_string ( size_string ) if crop size [ :width ] = get_base_dimensions [ :width ] if size [ :width ] . zero? size [ :height ] = get_base_dimensions [ :height ] if size [ :height ] . zero? size = reduce_to_image ( size ) else size = get_base_dimen...
Returns a size value String for the thumbnail used in essence picture editors .
5,064
def crop ( size , crop_from = nil , crop_size = nil , upsample = false ) raise "No size given!" if size . empty? render_to = sizes_from_string ( size ) if crop_from && crop_size top_left = point_from_string ( crop_from ) crop_dimensions = sizes_from_string ( crop_size ) xy_crop_resize ( render_to , top_left , crop_dime...
Returns the rendered cropped image . Tries to use the crop_from and crop_size parameters . When they can t be parsed it just crops from the center .
5,065
def size_when_fitting ( target , dimensions = get_base_dimensions ) zoom = [ dimensions [ :width ] . to_f / target [ :width ] , dimensions [ :height ] . to_f / target [ :height ] ] . max if zoom == 0.0 width = target [ :width ] height = target [ :height ] else width = ( dimensions [ :width ] / zoom ) . round height = (...
This function takes a target and a base dimensions hash and returns the dimensions of the image when the base dimensions hash fills the target .
5,066
def center_crop ( dimensions , upsample ) if is_smaller_than ( dimensions ) && upsample == false dimensions = reduce_to_image ( dimensions ) end image_file . thumb ( "#{dimensions_to_string(dimensions)}#" ) end
Uses imagemagick to make a centercropped thumbnail . Does not scale the image up .
5,067
def xy_crop_resize ( dimensions , top_left , crop_dimensions , upsample ) crop_argument = "-crop #{dimensions_to_string(crop_dimensions)}" crop_argument += "+#{top_left[:x]}+#{top_left[:y]}" resize_argument = "-resize #{dimensions_to_string(dimensions)}" resize_argument += ">" unless upsample image_file . convert "#{cr...
Use imagemagick to custom crop an image . Uses - thumbnail for better performance when resizing .
5,068
def reduce_to_image ( dimensions ) { width : [ dimensions [ :width ] , image_file_width ] . min , height : [ dimensions [ :height ] , image_file_height ] . min } end
Used when centercropping .
5,069
def previous ( options = { } ) pages = self_and_siblings . where ( 'lft < ?' , lft ) select_page ( pages , options . merge ( order : :desc ) ) end
Returns the previous page on the same level or nil .
5,070
def publish! current_time = Time . current update_columns ( published_at : current_time , public_on : already_public_for? ( current_time ) ? public_on : current_time , public_until : still_public_for? ( current_time ) ? public_until : nil ) end
Publishes the page .
5,071
def create_legacy_url if active_record_5_1? former_urlname = urlname_before_last_save else former_urlname = urlname_was end legacy_urls . find_or_create_by ( urlname : former_urlname ) end
Stores the old urlname in a LegacyPageUrl
5,072
def cache_page? return false unless caching_enabled? page_layout = PageLayout . get ( self . page_layout ) page_layout [ 'cache' ] != false && page_layout [ 'searchresults' ] != true end
Returns true if the page cache control headers should be set .
5,073
def tag_list = ( tags ) case tags when String self . tag_names = tags . split ( / \s / ) when Array self . tag_names = tags end end
Set a list of tags Pass a String with comma separated tag names or an Array of tag names
5,074
def download response . headers [ 'Content-Length' ] = @attachment . file . size . to_s send_file ( @attachment . file . path , { filename : @attachment . file_name , type : @attachment . file_mime_type } ) end
sends file as attachment . aka download
5,075
def security_token ( params = { } ) params = params . dup . stringify_keys params . update ( { 'crop' => params [ 'crop' ] ? 'crop' : nil , 'id' => id } ) PictureAttributes . secure ( params ) end
Returns a security token for signed picture rendering requests .
5,076
def update_urlname! new_urlname = nested_url_name ( slug ) if urlname != new_urlname legacy_urls . create ( urlname : urlname ) update_column ( :urlname , new_urlname ) end end
Makes a slug of all ancestors urlnames including mine and delimit them be slash . So the whole path is stored as urlname in the database .
5,077
def convert_url_name ( value ) url_name = convert_to_urlname ( value . blank? ? name : value ) if url_name . length < 3 ( '-' * ( 3 - url_name . length ) ) + url_name else url_name end end
Converts the given name into an url friendly string .
5,078
def show @page = @element . page @options = params [ :options ] respond_to do | format | format . html format . js { @container_id = params [ :container_id ] } end end
== Renders the element view partial
5,079
def render_icon ( icon_class , options = { } ) options = { style : 'solid' } . merge ( options ) classes = [ "icon fa-fw" , "fa-#{icon_class}" , "fa#{options[:style].first}" , options [ :size ] ? "fa-#{options[:size]}" : nil , options [ :transform ] ? "fa-#{options[:transform]}" : nil , options [ :class ] ] . compact c...
Render a Fontawesome icon
5,080
def page_or_find ( page ) if page . is_a? ( String ) page = Language . current . pages . find_by ( page_layout : page ) end if page . blank? warning ( "No Page found for #{page.inspect}" ) return else page end end
Checks if the given argument is a String or a Page object . If a String is given it tries to find the page via page_layout Logs a warning if no page is given .
5,081
def load_page @page ||= Language . current . pages . contentpages . find_by ( urlname : params [ :urlname ] , language_code : params [ :locale ] || Language . current . code ) end
== Loads page by urlname
5,082
def render_fresh_page? must_not_cache? || stale? ( etag : page_etag , last_modified : @page . published_at , public : ! @page . restricted , template : 'pages/show' ) end
We only render the page if either the cache is disabled for this page or the cache is stale because it s been republished by the user .
5,083
def render_essence_view_by_name ( element , name , options = { } , html_options = { } ) if element . blank? warning ( 'Element is nil' ) return "" end content = element . content_by_name ( name ) render_essence_view ( content , options , html_options ) end
Renders the + Essence + view partial from + Element + by name .
5,084
def render_essence ( content , part = :view , options = { } , html_options = { } ) options = { for_view : { } , for_editor : { } } . update ( options ) if content . nil? return part == :view ? "" : warning ( 'Content is nil' , Alchemy . t ( :content_not_found ) ) elsif content . essence . nil? return part == :view ? ""...
Renders the + Esssence + partial for given + Content + .
5,085
def current_alchemy_user current_user_method = Alchemy . current_user_method raise NoCurrentUserFoundError if ! respond_to? ( current_user_method , true ) send current_user_method end
The current authorized user .
5,086
def set_alchemy_language ( lang = nil ) if lang @language = lang . is_a? ( Language ) ? lang : load_alchemy_language_from_id_or_code ( lang ) else @language = load_alchemy_language_from_params || load_alchemy_language_from_session || Language . default end store_current_alchemy_language ( @language ) end
Try to find and stores current language for Alchemy .
5,087
def store_current_alchemy_language ( language ) if language && language . id session [ :alchemy_language_id ] = language . id Language . current = language end end
Stores language s id in the session .
5,088
def render_elements ( options = { } ) options = { from_page : @page , render_format : 'html' } . update ( options ) if options [ :sort_by ] Alchemy :: Deprecation . warn "options[:sort_by] has been removed without replacement. " "Please implement your own element sorting by passing a custom finder instance to options[:...
Renders elements from given page
5,089
def element_preview_code ( element ) if respond_to? ( :tag_options ) tag_options ( element_preview_code_attributes ( element ) ) else tag_builder . tag_options ( element_preview_code_attributes ( element ) ) end end
Renders the HTML tag attributes required for preview mode .
5,090
def element_tags_attributes ( element , options = { } ) options = { formatter : lambda { | tags | tags . join ( ' ' ) } } . merge ( options ) return { } if ! element . taggable? || element . tag_list . blank? { 'data-element-tags' => options [ :formatter ] . call ( element . tag_list ) } end
Returns the element s tags information as an attribute hash .
5,091
def next ( name = nil ) elements = page . elements . published . where ( 'position > ?' , position ) select_element ( elements , name , :asc ) end
Returns next public element from same page .
5,092
def copy_nested_elements_to ( target_element ) nested_elements . map do | nested_element | Element . copy ( nested_element , { parent_element_id : target_element . id , page_id : target_element . page_id } ) end end
Copy all nested elements from current element to given target element .
5,093
def essence_error_messages messages = [ ] essence_errors . each do | content_name , errors | errors . each do | error | messages << Alchemy . t ( "#{name}.#{content_name}.#{error}" , scope : 'content_validations' , default : [ "fields.#{content_name}.#{error}" . to_sym , "errors.#{error}" . to_sym ] , field : Content ....
Essence validation errors
5,094
def language_links ( options = { } ) options = { linkname : 'name' , show_title : true , spacer : '' , reverse : false } . merge ( options ) languages = Language . on_current_site . published . with_root_page . order ( "name #{options[:reverse] ? 'DESC' : 'ASC'}" ) return nil if languages . count < 2 render ( partial :...
Renders links to language root pages of all published languages .
5,095
def render_navigation ( options = { } , html_options = { } ) options = { submenu : false , all_sub_menues : false , from_page : @root_page || Language . current_root_page , spacer : nil , navigation_partial : 'alchemy/navigation/renderer' , navigation_link_partial : 'alchemy/navigation/link' , show_nonactive : false , ...
Renders the navigation .
5,096
def external_page_css_class ( page ) return nil if ! page . redirects_to_external? request . path . split ( '/' ) . delete_if ( & :blank? ) . first == page . urlname . gsub ( / \/ / , '' ) ? 'active' : nil end
Returns + active + if the given external page is in the current url path or + nil + .
5,097
def render_breadcrumb ( options = { } ) options = { separator : ">" , page : @page , restricted_only : false , reverse : false , link_active_page : false } . merge ( options ) pages = Page . ancestors_for ( options [ :page ] ) . accessible_by ( current_ability , :see ) if options . delete ( :restricted_only ) pages = p...
Returns page links in a breadcrumb beginning from root to current page .
5,098
def page_title ( options = { } ) return "" if @page . title . blank? options = { prefix : "" , suffix : "" , separator : "" } . update ( options ) title_parts = [ options [ :prefix ] ] if response . status == 200 title_parts << @page . title else title_parts << response . status end title_parts << options [ :suffix ] t...
Returns current page title
5,099
def index if can? :edit_content , Alchemy :: Page @pages = Page . all else @pages = Page . accessible_by ( current_ability , :index ) end if params [ :page_layout ] . present? @pages = @pages . where ( page_layout : params [ :page_layout ] ) end render json : @pages , adapter : :json , root : :pages end
Returns all pages as json object